1

一部のユーザーに関係のないフォームの特定のセクションを非表示にする Web ページの 1 つに次のコードがあります。ただし、何らかの理由で selectAttending 変数のみがバインドされています。テキスト ボックスと 2 つのドロップダウンの値を渡したいのですが、このドロップダウンの値しか渡されません。助言がありますか?

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

1 に答える 1

0

jQuery の選択により、要素のリストが作成されます。たとえば、jQuery 選択関数を使用する場合、$複数の処理を行う場合は、結果を反復処理する必要があります。のような関数を使ってみてくださいeachこの S/O questionと関連するjQuery docsを参照してください。

于 2012-04-12T18:33:22.007 に答える