我想在每個組中標識(提醒)每個選項/選項值。 但我需要一個推...jquery選擇器 - 標識每個組中的每個選項/選項值
<script src="jquery.mobile/jquery.js"></script>
<div id="groupA" class="preGroups">
<div id="section-A1">
<input name="SRPR1" type="text">
<select name='ACTC' id='preAction' >
<option value='007'>Stolen</option>
<option value='008'>Tampered</option>
</select>
</div>
<div id="section-A2">
<input name="SRPR1" type="text">
<select name='ACTC' id='preAction' >
<option value='007'>Stolen</option>
<option value='008'>Tampered</option>
</select>
</div>
</div>
<div id="groupB" class="preGroups">
<div id="section-B1">
<input name="SRPR1" type="text">
<select name='ACTC' id='preAction' >
<option value='007'>Stolen</option>
<option value='008'>Tampered</option>
</select>
</div>
<div id="section-B2">
<input name="SRPR1" type="text">
<select name='ACTC' id='preAction' >
<option value='007'>Stolen</option>
<option value='008'>Tampered</option>
</select>
</div>
<script>
$(document).ready(function()
{
// iterate through each group in groups
groups = $('div[id^="group"]');
$.each(groups, function(key, group) {
fnValidateGroup($(group));
});
// validation for reason codes in a specific Group
function fnValidateGroup(currentGroup){
selects = $(currentGroup).find('select[name="ACTC"]');
$.each(selects, function(key, activity) {
// show me activity seelctec in each case
alert($(activity).val) ;
});
}
});
</script>
* 編輯* 輸出應該是這樣的:
new Group
007
008
new Group
007
007
* 編輯* 這是我來到你的幫助的答案...
$(document).ready(function()
{
// iterate through each group in groups
groups = $('div[id^="group"]');
$.each(groups, function() {
console.log("New Group");
fnValidateGroup(this);
});
// validation for reason codes in a specific Group
function fnValidateGroup(currentGroup){
selects = $(currentGroup).find('select[name="ACTC"]');
$.each(selects, function(key, activity) {
// show me activity seelctec in each case
console.log(($(activity)).val());
});
}
});
您可能會注意到差異下注jQuery的每個功能,其中有兩個。 [這一個](http://api.jquery.com/each/)遍歷jQuery對象。 [和此](http://api.jquery.com/jQuery.each/)迭代JavaScript對象。出於你的目的,第一個更容易使用,因爲你有jQuery對象。那麼你不需要引用關鍵的值變量。你會看到我在我的答案中使用了第一個。 – BZink