2011-02-10 102 views
0

這是我的最終代碼:如果選擇了「其他」下拉菜單,則會出現輸入框?

<script type="text/javascript"> 
jQuery(function() { 
    jQuery("#company").change(function() { 
     var val = jQuery(this).val(); 
     if(val == 'other') { 
      jQuery('input[name="other"]').fadeIn('slow'); 
     } else { 
      jQuery('input[name="other"]').fadeOut('slow')(); 
     } 
    }); 
}); 
</script> 

回答

7
$(function() { 
    $("#dropdown").change(function() { 
     var val = $(this).val(); 
     if(val == 'other') { 
      $('input[name="other"]').show(); 
     } else { 
      $('input[name="other"]').hide(); 
     } 
    }).change(); 
}); 

更新。如box9建議的那樣,因爲您希望該功能在頁面加載時觸發。

+0

感謝您的快速回復,我真的很感激。我已經使用過您的代碼,並且在頁面加載時顯示輸入和選擇框,即使未選擇「其他」也是如此。我已經在主帖子中再次發佈了我的代碼。 – Latox 2011-02-10 05:10:24