如何在選擇正確的下拉項目時顯示所需的輸入文本框。jQuery選項選擇
例子:
如果是選擇它會詢問有關域的詳細信息。
<label for="domainRequired">Domain required: </label>
<select name="domainRequired">
<option value="pleaseSelect">Please Select</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
更新:
HTML:
<label for="domainRequired">Domain required: </label>
<select name="domainRequired">
<option value="pleaseSelect">Please Select</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<label for="domaintobereged">Domain:</label><input name="domaintobereged" id="domaintobereged" type="text" placeholder="http://"/>
的jQuery:
<script type="text/javascript">
$(document).ready(function() {
$('#domainRequired').change(function() {
var $domain = $('#domaintobereged');
if ($(this).val() == 'yes') {
$domain.show();
} else {
$domain.hide();
}
});
});
</script>
我已加載我的jQuery在</body>
標籤上面的頁腳:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="http://#.co.nz/_assets/js/jquery-1.7.2.min.js"><\/script>')</script>
什麼是你說的這些輸入文本框? – BoltClock 2012-04-02 04:08:12
http://jsfiddle.net/zerkms/3XYMT/ – zerkms 2012-04-02 04:10:05
@zerkms移動回答,我會upvote它 – 2012-04-02 04:29:58