62,046
社区成员
发帖
与我相关
我的任务
分享
for (int i = 0; i < GridView1.Rows.Count; i++) {
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox");
chk.Attributes.Add("onclick", "chkCount(this)");
}
function chkCount() {
alert"1");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox checkBox = (CheckBox)e.Row.FindControl("checkbox1");
Literal RowNumber = (Literal)e.Row.FindControl("RowNumber");
string rowIndex = RowNumber.Text;
checkBox.Attributes.Add("onclick", "Checked(this,'" + rowIndex + "');");
}
}
function Checked(e, rowIndex) {
var i = parseInt(rowIndex);
var gridview = document.getElementById("GridView1");
var textbox = gridview.rows[i].cells[5].getElementsByTagName("input")[0];
if (e.checked) {
textbox.disabled = false;
textbox.style.backgroundColor = "#c2e9e6";
} else {
textbox.disabled = true;
textbox.style.backgroundColor = "";
}
}
alert"1");
而是一大堆具体的 js 代码,那么可能可以根据你说明的比较深入一点的机制来谈(因为这方面并没有规范的做法,都是根据“深度知识”来设计的,每一个应用系统的的技术都不太一样)。而当你看上去完全没有学过 asp.net 一系列控件在 html 端产生什么东西、以及 asp.net 服务器端页面对象生命周期模型的时候,其实谁也没有信心说你能把 web 编程进行下去。比如说你写某个 jQuery("#abc").text("1")
然后又要“传给后台”,这就从一开始就会越来越多的问题,无止境地问题。<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:CheckBox ID="CheckBox3" runat="server" />
</form>
</body>
<script>
$('input[name^="CheckBox"]').each(function (i, v) {
$(this).bind("click", function click() {
alert(i);
});
})
</script>
function chkCount(e) {
var row = e.parentNode.parentNode;
var rowIndex = row.rowIndex;
if (e.checked) {
alert("1");
} else {
alert("2");
}
debugger;
}