[英]Uncheck Selected checkbox on button click
I have already tried all the given methods to uncheck checkbox in jquery, please find my below code. 我已经尝试了所有给定的方法来取消选中jquery中的复选框,请找到下面的代码。
$('#btnDeleteEnterpriseID').click(function () {
$('#chkbox').prop('checked', false);
$('#chkbox').removeAttr('checked');
$('#chkbox').checked = false;
$('#chkbox').attr('checked', false);
$('#chkbox input:checkbox').attr('checked', false);
$('#chkbox input[type=checkbox]').removeAttr('checked');
});
Have tried with all methods that I could get till now. 尝试了到现在为止我可以使用的所有方法。
Below is the code for my checkbox and button. 以下是我的复选框和按钮的代码。
@helper DisplayMultiLine(string str)
{ foreach (string s in str.Split(new char[] { ',' }))
{ <input type="checkbox" id="chkbox" value="@s"class="edit-mode" />@s <br />}
}
Here, @DisplayMultiline is helper class which I used in Web Grid column as shown below, 在这里,@ DisplayMultiline是我在“ Web网格”列中使用的帮助器类,如下所示,
grid.Column(columnName: "EnterpriseID",
format:@<text><span class="display-mode">
<label id="EnterpriseId" ></label>
</span>@DisplayMultiLine(@item.EnterpriseId)</text>),
And I want this checkbox to get unchecked on click event of delete button, code for it given below. 我希望此复选框在删除按钮的单击事件中不被选中,其代码如下。
<button type="button" id="btnDeleteEnterpriseID"
value="Delete" class="cancel-user edit-mode" onclick="DeleteEnterpriseID()">Delete</button>
I am not getting my mistake, kindly assist. 我没有弄错,请帮忙。
Kindly note, I have not used all those possibilities together, I just wanted to tell that I have used almost all methods and have tried them one by one. 请注意,我并没有同时使用所有这些可能性,我只是想告诉我,我几乎使用了所有方法,并逐一尝试了它们。
You are generating duplicate identifiers in your foreach: 您正在foreach中生成重复的标识符:
@helper DisplayMultiLine(string str)
{ foreach (string s in str.Split(new char[] { ',' }))
{ <input type="checkbox" id="chkbox" value="@s"class="edit-mode" />@s <br />}
}
When you have multiple objects with the same id, jquery is having trouble to distinguish which one of them you aim at . 当您有多个具有相同ID的对象时,jquery很难区分您针对的对象是哪个 。
Jquery will either work only on the first one it will match or won't work at all . jQuery只能在第一个匹配的jQuery上起作用或根本不起作用 。 Find a way to distinguish between every check box .
找到一种方法来区分每个复选框 。 for example:
例如:
@helper DisplayMultiLine(string str)
int i = 0;
{ foreach (string s in str.Split(new char[] { ',' }))
{ <input type="checkbox" id="chkbox" + i value="@s"class="edit-mode" />@s
} }
i++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.