如何显示/隐藏基于jQuery的选择textarea? [英] how to show/hide textarea based on select in jquery?
本文介绍了如何显示/隐藏基于jQuery的选择textarea?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个选择字段和一个textarea.我试图隐藏/显示我制作的选择类型的功能中的文本区域:
i have a select field and a textarea one. And i am trying to hide/show the textarea in function of the select type i make:
<select id="select" name="management">
<option value="0" selected="">Select One</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<textarea id="textarea" name="searching_gig_des" wrap="VIRTUAL" cols="50" rows="5"></textarea>
var textarea = $('textarea');.
var select = $('#select').val();
textarea.hide();
if (select == '1'){
textarea.show();
}
if (select == '0'){
textarea.hide();
}
或 jsfiddle
有什么想法吗?
谢谢
推荐答案
您有一些语法错误,而且您没有为select
You have a few syntax errors, plus you're not binding the change
event
for the select
$('#select').change(function(){
var textarea = $('textarea');
var select = $(this).val();
textarea.hide();
if (select == '1'){
textarea.show();
}
if (select == '0'){
textarea.hide();
}
});
这篇关于如何显示/隐藏基于jQuery的选择textarea?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文