2015-04-04 59 views
1

選擇我有形式包含名多發性輸入,比如objectName[unique_guid].propertyName通過jQuery的面膜

只有unique_guid是我投入不同。

<input id="a_a" name="ObjectName[b15865be-629c-43b6-b1a6-e614d3ffeb67].Color" type="hidden" value="1"> 
<input id="b_b" name="ObjectName[8867e8e4-429f-4180-89e3-62bf505fcf5d].Level" type="hidden" value="2"> 

怎麼可以選擇所有與jQuery的輸入?

+1

你能PLS添加爲HTML? – 2015-04-04 05:38:29

+2

'$('[name^=「objectName」]')'[屬性以選擇器開始](https://api.jquery.com/attribute-starts-with-selector/)。 – 2015-04-04 05:39:27

回答

3

有各種可用的基於屬性的選擇器。

使用Attribute starts with selector ^=

$('input[name^="ObjectName"]') 

或在您的案件$= - 屬性結尾。

$('input[name$=".Color"]') 

組合選擇:

$('input[name^="ObjectName"][name$=".Color"]') //If your PropertyName is static. 
+0

投票完美答案 – 2015-04-04 05:46:47