Javascript JQuery只查看一个DIV ID来获取值

Javascript JQuery只查看一个DIV ID来获取值,javascript,jquery,Javascript,Jquery,我的一个网页上有以下代码,其中隐藏了表单中与某些用户无关的某些部分。但是,由于某些原因,现在只绑定SelectAttenting变量。我想传递一个文本框和两个下拉列表的值,但只传递这个下拉列表的值。有什么建议吗 <html> <input class="input-xlarge focused" id="txtName" type="text" > <select name=selectAttending id=selectAttending>

我的一个网页上有以下代码,其中隐藏了表单中与某些用户无关的某些部分。但是,由于某些原因,现在只绑定SelectAttenting变量。我想传递一个文本框和两个下拉列表的值,但只传递这个下拉列表的值。有什么建议吗

<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>

选择一个。。。
对
不
选择一个。。。
男性
女性
$(“#选择主治”)。更改(功能(){
如果($('#selectAttenting option:selected')。text()=“否”){
$(“#ifAttending”).hide();
}else if($('#selectAttenting option:selected')。text()=“是”){
$('#ifAttending').show();
}否则{
$('#ifAttending').show();
} 
});      

jQuery选项创建元素列表;当您使用jQuery选择函数(例如,
$
)时,如果要处理多个结果,则需要遍历结果。尝试使用类似于
each
的函数。请参阅,以及相关的。

是否有多个具有相同ID的HTML元素?如果是这样,您需要将它们更改为类。ID本身应该是唯一的,因此如果您有多个具有相同ID的元素,则JavaScript将只使用第一个元素。显然,必须为每个元素设置name属性,才能使其与ID一样正常工作。我只设置了ID。