在javascript中获取生成的复选框ID

时间:2016-06-22 07:35:17

标签: javascript asp.net

尝试获取生成的复选框ID

当前复选框代码

<asp:CheckBox ID="CheckBox_select"  type="checkbox" runat="server" onclick="javascript:CheckCheckBox(this);" />

生成:

<input id="ContentPlaceHolder1_GridView_reminderList_CheckBox_select_10" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView_reminderList$ctl12$CheckBox_select" onclick="javascript:CheckCheckBox(this);">

<input id="ContentPlaceHolder1_GridView_reminderList_CheckBox_select_11" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView_reminderList$ctl11$CheckBox_select" onclick="javascript:CheckCheckBox(this);">

如何获取ContentPlaceHolder1_GridView_reminderList_CheckBox_select_10&amp;在JavaScript中甚至在asp.net中的ContentPlaceHolder1_GridView_reminderList_CheckBox_select_11?

1 个答案:

答案 0 :(得分:0)

  

阅读Element.id属性

&#13;
&#13;
function CheckCheckBox(elem) {
  console.log(elem.id);
}
&#13;
<input id="ContentPlaceHolder1_GridView_reminderList_CheckBox_select_10" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView_reminderList$ctl12$CheckBox_select" onclick="javascript:CheckCheckBox(this);">

<input id="ContentPlaceHolder1_GridView_reminderList_CheckBox_select_11" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView_reminderList$ctl11$CheckBox_select" onclick="javascript:CheckCheckBox(this);">
&#13;
&#13;
&#13;