jQuery jQuery获取所有带有名称的选中复选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17736856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:52:00  来源:igfitidea点击:

jQuery Get all checked checkboxes with name

javascriptjqueryarrays

提问by IEnumerable

Im trying to get all checked boxes with a name if images[].

如果图像[],我试图获取所有带有名称的复选框。

I would usually

我通常会

 imgs = $('input:checkbox[name=images]:checked').map(function() { return this.value; }).get();

The below code is what I have tried and isnt working.

下面的代码是我尝试过但不起作用的代码。

 imgs = $('input:checkbox[name=images[]]:checked').map(function() { return this.value; }).get();

回答by adeneo

You should escape the brackets (adding quotes would also avoid the problem, but escaping special characters is still good practice):

你应该转义括号(添加引号也可以避免这个问题,但转义特殊字符仍然是一个好习惯):

imgs = $('input[type="checkbox"][name="images\[\]"]:checked').map(function() { return this.value; }).get();