通过jQuery的ID列表获取多个元素 [英] Get multiple elements by a list of id's with jQuery

查看:810
本文介绍了通过jQuery的ID列表获取多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中有

<input type="checkbox" id="1234">
<input type="checkbox" id="2345">
<input type="checkbox" id="3456">
<input type="checkbox" id="4567">
<input type="checkbox" id="5678">

以及ID为1234 2345 3456#1234 #2345 #3456

我想获取id在id列表中的列表的所有元素

I want to get all the element of the list whose id is in the list of id

我尝试$(":checkbox").attr('id', items_id);var items_cb = $(":checkbox[id='items_id']");,其中items_id是项目列表,但是不起作用.

I try $(":checkbox").attr('id', items_id); and var items_cb = $(":checkbox[id='items_id']"); where items_id is the list of item, but it doesn't work.

推荐答案

只需尝试将所有ID放在选择器中,并以逗号分隔:

Just try to put all id's in selector separated by comma:

$('#1234, #2345, #3456')...

代码: http://jsfiddle.net/3df6W/

P.S. ID不能以数字开头.

P.S. ID's shouldn't start with digits.

这篇关于通过jQuery的ID列表获取多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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