jQuery的 - 选择具有JS数组名称的所有复选框 [英] jquery - select all checkboxes with js array name

查看:129
本文介绍了jQuery的 - 选择具有JS数组名称的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个jQuery检查所有功能,在这样的形式:
<一href=\"http://jetlogs.org/jquery/jquery_select_all.html\">http://jetlogs.org/jquery/jquery_select_all.html

I want to use a JQuery "check all" function in a form like this: http://jetlogs.org/jquery/jquery_select_all.html

我的问题是我生成我的形式从一个PHP脚本,我不知道我会到底有多少复选框要提前。
我用的是数组命名约定,能得到我的$ _ POST数据所有选中的复选框值...
所以我的复选框是这样的:

My problem is I am generating my form from a php script, and I don't know exactly how many checkboxes I will have in advance. I use the "array" naming convention to be able to get all the selected checkbox values in my $_POST data... so my checkboxes are like that:

<input type="checkbox" name="items[]" value="<?php echo $id ?>">

但这个jQuery声明不起作用:

but this JQuery declaration does not work:

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

大概是因为[]在我的项目搅乱JQuery的声明结束......我试着写@名称=项目[]这样的:@名称=项目[],并把一些反斜杠前的[和]所以他们不被视为特殊字符,但它没有工作......

probably because the "[]" at the end of my "items" messes up the JQuery declaration... I tried to write @name=items[] like that: "@name=items[]", and to put some anti-slash before the [ and ] so they're not considered as special characters but it didnt work...

如果有人知道一个解决方案,并愿意分享这将会是伟大的! :)

If someone knows a solution and is willing to share it'd be great!! :)

推荐答案

逃生与 \\\\ (无空格)内部括号 - 它应该解决这个问题。

Escape internal brackets with \\(no space) - it should fix the problem.

这选择对我的作品:

$('input[name=items\\[\\]]')

这篇关于jQuery的 - 选择具有JS数组名称的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆