2014-06-10 24 views
0

這是我一直在努力的事情。以下是單色色板的html。在此頁面上可能會有數百種顏色色板。會有一個默認值,一旦加載頁面,就會出現一個選中的單選按鈕。試圖檢索選中的單選按鈕的前一個兄弟值的值

我想要檢索的,並放入一個變量是 選中的輸入是一個同級的價值,而之前是隱藏型的(我已經標有註釋)

在我查看的所有例子中,檢索選中的單選按鈕的值時, 沒有考慮到該名稱是數組的一部分並相應地命名。

$('input [name = id []]:checked').. and this does not work。

<div class="color-swatch-wrapper"> 
<input type="hidden" name="descriptive[9]" value="SL01" class="swatch-descriptive-name" /><!-- trying to retrieve this value --> 
<input type="radio" name="id[9]" value="70" checked="checked" id="attrib-9-70" class="threads-radio-btn" /> 
<label class="attribsRadioButton two thread-opts" for="attrib-9-70">SL01<br /> 
    <img src="images/attributes/SL01.jpg" alt="" width="260" height="320" /> 
</label> 
</div> 

我的僞代碼將改爲類似:

descriptiveName = ($('input[name=id[]]:checked', '#nameOfForm').prev.().val()) 

,其中分組是兄弟包含描述性名稱前值。 非常感謝提前!

回答

1

它不工作,因爲你特林找到名爲元素正是「ID []」 ...

爲了讓期望的結果,你可以找到與「ID =」開頭的元素:

$('input[name^="id["]:checked').prev().val() 
+0

非常感謝, – TopTomato