我有一个列表视图,其中包含n个复选框。我想在点击第一个复选框时启用/禁用。 我在jquery中编写了一个代码。但它取了页面中的所有复选框。我需要启用/禁用所选行。
function EnableCurrentRowControls(chkID)
{
var chkBox = document.getElementById(chkID);
var chkIDList = document.getElementsByTagName("input");
for (i = 0; i < chkIDList.length; i++)
{
if (chkIDList[i].type == "checkbox" && chkIDList[i].id != chkBox.id) {
if (chkIDList[i].type == "checkbox" && chkIDList[i].id != chkBox.id)
{
chkIDList[i].enabled = false;
}
}
}
}
在ListView控件中调用函数
<asp:CheckBox ID="chkUserBoardMaping" OnClick="javascript:EnableCurrentRowControls(this.id)"
runat="server" />
请看看并给我建议..
答案 0 :(得分:1)
可能会尝试这样的事情:
function EnableCurrentRowControls(element) {
if ($(element).closest('tr').find('input[type=checkbox][id*=chkUserBoardMaping]').is(':checked')) {
$(element).closest('tr').find('input[type=text][id*=myTextBox]').removeAttr("disabled");
}
else {
$(element).closest('tr').find('input[type=text][id*=myTextBox]').prop("disabled");
}
}
你还必须改变它 (1.仅将此作为论据 2.将onclick事件更改为onchange):
<asp:CheckBox ID="chkUserBoardMaping" onchange="javascript:EnableCurrentRowControls(this)"
runat="server" />
请确保您更改了控件(myTextBox)名称!