1
我的一个网页上隐藏了某些表单的某些部分与某些用户无关的代码。但是,由于某种原因,现在只有selectAttanding变量被绑定。我想传递一个文本框和两个下拉列表的值,但只传递此下拉列表的值。有什么建议么?JQuery仅查看一个DIV ID以获取值
<html>
<input class="input-xlarge focused" id="txtName" type="text" >
<select name=selectAttending id=selectAttending>
<option>Select One...</option>
<option>Yes</option>
<option>No</option>
</select>
<select id=selectGender>
<option selected="selected">Select One...</option>
<option>Male</option>
<option>Female</option>
</select>
<script language=javascript>
$("#selectAttending").change(function() {
if ($('#selectAttending option:selected').text() == "No") {
$('#ifAttending').hide();
} else if ($('#selectAttending option:selected').text() == "Yes") {
$('#ifAttending').show();
} else {
$('#ifAttending').show();
}
});
</script>
你有多个具有相同ID的HTML元素吗?如果是这样,你需要将它们改为类。 ID本质上应该是唯一的,所以如果你有多个具有相同ID的元素,那么JavaScript将只使用第一个。 – 2012-04-12 18:18:14
请发布您的HTML。 – j08691 2012-04-12 18:22:29
很明显,必须为每个元素设置name属性以使其正常工作以及ID。我只设置了ID。 – Geekender 2012-04-12 18:30:46