我想通过Jquery每个函数迭代特定div中的多个选择选项。然后,如果有至少一个空字段,则循环断开并将0设置为reqCourseFlag
变量。我的实现如下,但它不会循环
HTML:
<div id="IENG349ReqCourses" class="reqCourses">
<center>
<table>
<caption style="color:#f00;">Please select your grades for required courses.</caption>
<tr>
<td valign="middle">
<label>IENG 102 - Intro to IE:</label>
</td>
<td>
<select id="intershipTypeBox" name="IENG102Grade">
<option value="">--select--</option>
<option value="NOT TAKEN">NOT TAKEN</option>
<option value="TAKING">TAKING</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
<option value="C+">C+</option>
<option value="C">C</option>
<option value="F">F</option>
</select>
</td>
</tr>
<tr>
<td valign="middle">
<label>IENG104 - Comp. Aided Drawing:</label>
</td>
<td>
<select id="intershipTypeBox" name="IENG104Grade">
<option value="">--select--</option>
<option value="NOT TAKEN">NOT TAKEN</option>
<option value="TAKING">TAKING</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
<option value="C+">C+</option>
<option value="C">C</option>
<option value="F">F</option>
</select>
</td>
</tr>
<tr>
<td valign="middle">
<label>IENG 211 - Prob. In Eng.:</label>
</td>
<td>
<select id="intershipTypeBox" name="IENG211Grade">
<option value="">--select--</option>
<option value="NOT TAKEN">NOT TAKEN</option>
<option value="TAKING">TAKING</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
<option value="C+">C+</option>
<option value="C">C</option>
<option value="F">F</option>
</select>
</td>
</tr>
<tr>
<td valign="middle">
<label>IENG 212 - Eng. Statistics:</label>
</td>
<td>
<select id="intershipTypeBox" name="IENG212Grade">
<option value="">--select--</option>
<option value="NOT TAKEN">NOT TAKEN</option>
<option value="TAKING">TAKING</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
<option value="C+">C+</option>
<option value="C">C</option>
<option value="F">F</option>
</select>
</td>
</tr>
<tr>
<td valign="middle">
<label>IENG 221 - Work Syst. Analysis and Design:</label>
</td>
<td>
<select id="intershipTypeBox" name="IENG221Grade">
<option value="">--select--</option>
<option value="NOT TAKEN">NOT TAKEN</option>
<option value="TAKING">TAKING</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
<option value="C+">C+</option>
<option value="C">C</option>
<option value="F">F</option>
</select>
</td>
</tr>
</table>
</center>
</div>
$('div.#IENG349ReqCourses: select> option:selected').each(function() {
var value = $(this).val();
if(value === ""){
reqCourseFlag = 0;
return false;
}
});
任何帮助都会得到满足。
答案 0 :(得分:1)
您的选择器不正确,您不需要.
或:
$('div#IENG349ReqCourses select> option:selected').each(function () {