简体   繁体   English

按具有类似属性的数组的属性选择dom元素

[英]Select dom elements by attributes having array like attributes

I have many elements that are structured to get them in array like mapping on server side. 我有许多元素被构造成将它们放在数组中,就像服务器端的映射一样。

<input type="CHECKBOX" id="478" value="1" name="data[GroupInfo][student][478]" onclick="return updateValues('478')">
<input type="CHECKBOX" id="490" value="1" name="data[GroupInfo][student][490]" onclick="return updateValues('490')">

<input type="CHECKBOX" id="478" value="1" name="data[ClassInfo][student][478]" onclick="return updateValues('478')">
<input type="CHECKBOX" id="490" value="1" name="data[ClassInfo][student][490]" onclick="return updateValues('490')">

so on... Now, I want to select them using their name attribute like 所以......现在,我想用他们的名字属性来选择它们

$("[name^=data[ClassInfo][student]]");

but this won't work I tried to escape barckets to. 但这不起作用我试图逃离barckets。

$("[name^=data\[ClassInfo\]\[student\]]");

but no luck; 但没有运气;

I want to select them using name attribute. 我想使用name属性选择它们。

Just wrap the attribute value in "" 只需将属性值包装在""

$('input[name^="data[ClassInfo][student]"]')

Demo: Fiddle 演示: 小提琴

Try: 尝试:

// For exact element
    $('input[name=data[GroupInfo][student][478]]');

Or 要么

// For list of elements
    $('input[name^=data[GroupInfo][student]]');

You can see more here 你可以在这里看到更多

尝试这个:

$("[name^='data[ClassInfo][student]']");//Wrap in the single quotes
$('input[name*="data[ClassInfo][student]"]') // matches those that contain 'data[ClassInfo][student]'

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

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