Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery一次调用多个操作_Jquery_Performance_Checkbox - Fatal编程技术网

jQuery一次调用多个操作

jQuery一次调用多个操作,jquery,performance,checkbox,Jquery,Performance,Checkbox,在阅读jQuery性能的几个指导原则后,我发现了以下功能: 而不是做: $('#legendGallery).draggable({containment:'#container'}); $('#caption').draggable({containment:'#container'}); $('#controls').draggable({containment:'#container'}); 这样做: $('#legendGallery, #caption, #controls').dr

在阅读jQuery性能的几个指导原则后,我发现了以下功能:

而不是做:

$('#legendGallery).draggable({containment:'#container'});
$('#caption').draggable({containment:'#container'});
$('#controls').draggable({containment:'#container'});
这样做:

$('#legendGallery, #caption, #controls').draggable({containment:'#container'});
(对jQuery引擎的一次调用应用了多个操作)

我想将此概念应用于一系列复选框:

<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m1" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m2" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m3" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m4" />
$('input:checkbox[name="chl_wms\[\]"][value="m1"]', 'input:checkbox[name="chl_wms\[\]"][value="m2"]', 'input:checkbox[name="chl_wms\[\]"][value="m3"]).prop('disabled', true);
但它不起作用,没有错误,也没有采取任何行动

有没有更好的方法来定义选择器? 有没有一种方法可以使用一个调用来执行该命令


谢谢

也许我遗漏了什么,但为什么你不能这样做:

$('.largecheckbox').attr('disabled', 'disabled');

您的选择器中似乎有一个输入错误。另外,jQuery转义字符是
\\
,每个选择器都应该是一个字符串。考虑到这一点,应该:

$('input:checkbox[name="chk_wms\\[\\]"][value="m1"], input:checkbox[name="chk_wms\\[\\]"][value="m2"], input:checkbox[name="chk_wms\\[\\]"][value="m3"]').prop('disabled', true);
通过修正它应该工作

另一种比属性选择器性能更好的方法是使用类。例如:

<input type="checkbox" class="largecheckbox flag-disabled" name="chk_wms[]" value="m1" />
<input type="checkbox" class="largecheckbox flag-disabled" name="chk_wms[]" value="m2" />
<input type="checkbox" class="largecheckbox flag-disabled" name="chk_wms[]" value="m3" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m4" />    
----
$(".flag-disabled").prop("disabled", "disabled");

----
$(.flag disabled”).prop(“disabled”、“disabled”);
或者更好的是,使用ID:

<input type="checkbox" class="largecheckbox" id="chk_wms[m1]" name="chk_wms[]" value="m1" />
<input type="checkbox" class="largecheckbox" id="chk_wms[m2]" name="chk_wms[]" value="m2" />
<input type="checkbox" class="largecheckbox" id="chk_wms[m3]" name="chk_wms[]" value="m3" />
<input type="checkbox" class="largecheckbox" id="chk_wms[m4]" name="chk_wms[]" value="m4" />    
----
$("#chk_wms\\[m1\\], #chk_wms\\[m2\\], #chk_wms\\[m3\\]").attr("disabled", "disabled");

----
美元(“#chk_wms\\[m1\\],#chk_wms\\[m2\\],#chk_wms\\[m3\\]”)。属性(“禁用”,“禁用”);

$('input:checkbox[name=“ch**L**\u wms\[\]”)…
Typo?这将禁用所有复选框,OP将保留最后一个复选框,
m4
,处于活动状态。如果您对正则表达式很好,则很好。否则,禁用所有复选框并启用您想要的复选框。这不起作用吗?我只需要根据值禁用几个复选框。我有一个基于.l的常规单击事件argecheckbox类。该列表由50个复选框组成,具体取决于我重新加载地图时选中的复选框,但必须根据地图回调结果禁用多个复选框。$('input:checkbox[name=“chk\U wms\[\]]”][value=“m1”]、input:checkbox[name=“chk\U wms\[\]”][value=“m3”]、input:checkbox[name=“chk\U wms\[\]]、[value=“m3”]。prop('disabled','true);使用此方法,我得到了一个JS错误。同样,仅使用一个\n我将很快尝试第二个解决方案。该列表由50个元素组成,需要时间。第一个方法很好-只是在选择器的末尾缺少了一个类型-我还将编辑@rory_mccrossan answer以反映它-我相信你应该接受它伙计们,你太棒了!!T非常感谢汉克斯!