JQuery 只查看一个 DIV ID 即可获取值

JQuery only looking at one DIV ID to get values

本文关键字:ID DIV 获取 一个 JQuery      更新时间:2023-09-26

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

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

jQuery 选择会创建一个元素列表;当您使用 jQuery 选择函数时,例如 $ ,如果要处理多个结果,则需要循环访问结果。 尝试使用类似 each 的函数。 请参阅此 S/O 问题以及相关的 jQuery 文档。