我想识别(警告)每个组中的每个选择/选项值。 但我需要推动......
<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());
});
}
});
答案 0 :(得分:3)
这样的事情应该有效。你有什么尝试?
$("select").each(function(){
alert($(this).attr("name"));
$(this).children("option").each(function(){
alert($(this).html());
});
});
或者如果你想成对提醒他们(根据你的问题不确定)
$("select").each(function(){
var selectName = $(this).attr("name");
$(this).children("option").each(function(){
alert(selectName + " " + $(this).html());
});
});
这是您的小组验证
var groups = $("div[id^='group']");
groups.each(function(){
var thisGroup = $(this).attr("id");
$(this).find("option").each(function(){
alert(thisGroup + " " + $(this).val());
});
});
答案 1 :(得分:0)
$("div").each(function(){
$("select option",this).each(function(){
alert($(this).val());
});
});