简体   繁体   English

选择所有复选框命令jQuery,JavaScript

[英]select all checkboxes command jquery, javascript

I'm trying to get all of my checkboxes to be checked when clicking a link 我正在尝试在单击链接时选中所有复选框

looks like this: <a href='javascript:;' onclick="$.overall.selectAll();">select all</a> 看起来像这样: <a href='javascript:;' onclick="$.overall.selectAll();">select all</a> <a href='javascript:;' onclick="$.overall.selectAll();">select all</a>

inputs in a loop: <input type="checkbox" name="delete[$i]" value="1" /> 循环中<input type="checkbox" name="delete[$i]" value="1" /><input type="checkbox" name="delete[$i]" value="1" />

jquery code: jQuery代码:

var checked_status = this.checked;

    $("input[name=delete]").each(function() {
    this.checked = checked_status;
});

Can someone help me get it to check all.. ? 有人可以帮我检查一下吗?

When clicking at the select all link, nothing seems to happen.. (not even an error) 单击“全选”链接时,似乎什么也没有发生。(甚至没有错误)

Try the following. 尝试以下方法。

Updated. 更新。 The handler is tied to an anchor therefore there will be no this.checked attribute available. 该处理程序绑定到锚点,因此将没有this.checked属性可用。

$("#select_all").click(function(){
    $("input[name^=delete]").attr('checked',  'checked');  
});

jQuery教程: 全选复选框

您将要使用[name^=delete]选择器(“开头为”),因为您的复选框名称并不完全是 “ delete”,所以它们对于某些数字X而言是“ delete [X]”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM