簡體   English   中英

按具有類似屬性的數組的屬性選擇dom元素

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

我有許多元素被構造成將它們放在數組中,就像服務器端的映射一樣。

<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')">

所以......現在,我想用他們的名字屬性來選擇它們

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

但這不起作用我試圖逃離barckets。

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

但沒有運氣;

我想使用name屬性選擇它們。

只需將屬性值包裝在""

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

演示: 小提琴

嘗試:

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

要么

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

你可以在這里看到更多

嘗試這個:

$("[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