检查Checkbox时如何调用javascript函数

当此复选框位于gridview中时,如何在选中复选框时调用Javascript函数?

protected void AlteraStatusExpiraSeteDias_Click(object sender, EventArgs e) { for (int i = 0; i < grdImoveis2.Rows.Count; i++) { GridViewRow RowViewExpiraSeteDias = (GridViewRow)grdImoveis2.Rows[i]; CheckBox chk = (CheckBox)grdImoveis2.Rows[i].FindControl("chkExpiraSeteDias"); if (chk != null) { String codigo; if (chk.Checked) { codigo = (String)grdImoveis2.Rows[i].Cells[0].Text; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Registra", "AlteraStatus(codigo);", false); } } } }           ,             

没有复选框,当我放置一个图像并将链接href放到javascript时,它的工作原理!,但是带有复选框,不!

onclick属性添加到Checkbox标记并包含您要调用的javascript函数。

  

这应该对你有帮助

$('input:checkbox[ID$="chkExpiraTresDias"]').change(function() { alert('Hello world!'); });

我担心当你单击“插入”按钮然后做你必须做的事情时,你将不得不遍历Gridview。 像这样的东西:

 foreach (GridViewRow row in this.grdImoveis2.Rows) { if (row.RowType == DataControlRowType.DataRow) { CheckBox chk = row.Cells(0).FindControl("chkExpiraTresDias"); if (chk != null) { Response.Write(chk.Checked); //Do what you gotta do here if it's checked or not } } } 

祝好运。

Hanlet