Jquery 选中并取消选中所有复选框
为什么这个java脚本不能工作?请帮忙Jquery 选中并取消选中所有复选框,jquery,asp.net-mvc,Jquery,Asp.net Mvc,为什么这个java脚本不能工作?请帮忙 <script type="text/javascript"> $(document).ready(function() { $("#paradigm_all").click(function() { var checked_status = this.checked; $("input[@name=paradigm]").each(function() { this.checke
<script type="text/javascript">
$(document).ready(function() {
$("#paradigm_all").click(function() {
var checked_status = this.checked;
$("input[@name=paradigm]").each(function() {
this.checked = checked_status;
});
});
});
</script>
<table class="data-table">
<tr>
<th>
Redni br.
</th>
<th>
Br. Indexa
</th>
<th>
Prezime
</th>
<th>
Ime
</th>
<th>
<input id="paradigm_all" type="checkbox" />
</th>
</tr>
<% int rb = 1;%>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<input readonly="readonly" class="input-box" id="rb" type="text" name="rb" value="<%= Html.Encode(rb)%>" />
</td>
<td>
<input readonly="readonly" class="input-box" id="id_stud" type="text" name="id_stud" value="<%= Html.Encode(item.id_stud)%>" />
</td>
<td>
<%= Html.Encode(item.prezime)%>
</td>
<td>
<%= Html.Encode(item.ime)%>
</td>
<td>
<input name="paradigm" type="checkbox" />
</td>
</tr>
<% rb = rb + 1;%>
<% } %>
</table>
您的不起作用的原因是因为$'…'。选中的是返回值,而不是引用。要更改checked属性,您需要使用attr setter。哇,伙计,这里发生了一些疯狂的事情,我建议清理粘贴在这里的方式,我认为我们可以更好地阅读它。我认为您可以安全地从代码中删除每个属性
$("input[@name=paradigm]").attr('checked',checked_status);
在表的顶部添加复选框元素
$(document).ready(function() {
$("#paradigm_all").click(function() {
$("input[name=paradigm]").attr({checked: $(this).is(':checked')});
});
。。。等等
<table>
<tr>
<th>
<input type="checkbox" onclick="$('table:parent td input[type=checkbox]').attr('checked',$(this).attr('checked'));" />
</th>
第一个复选框选中表中的所有复选框。$document.readyfunction{$paradigm\u all.clickfunction{$'input[name=paradigm]'.attr'checked',true;};};你是说这个吗?你知道他用的是什么版本的jQuery吗?由于各种原因,并非每个人都可以使用最新版本。我使用了他所拥有的。代码是正确的,但是在name:$input[name=paradigm]前面没有@。attr{checked:$this.is':checked'};问题解决了。谢谢!!!
<tbody>
<tr>
<td><input type="checkbox" id="id-1" name="id[]" value="1" /></td>
</tr>
</tbody>
</table>