[英]Form Text Field becomes visible when dropdown-item is chosen
I need a text field inside a form that becomes visible only when a specified drop-down menu is chosen.我需要一个表单内的文本字段,该字段仅在选择指定的下拉菜单时才可见。 To be clear, the text box becomes clear by selecting a specific drop-down menu, not by submitting the form.
为了清楚起见,文本框通过选择特定的下拉菜单而不是通过提交表单变得清晰。 Ie, the page 'listens' for the a specific dropdown to be chosen and then through some methodology makes a text field visible for the user to fill in.
即,页面“侦听”要选择的特定下拉列表,然后通过某种方法使文本字段可见,供用户填写。
Basic elements in your form.表单中的基本元素。 Easiest way is to just use literal ID's for the fields.
最简单的方法是对字段使用文字 ID。
<form... >
<select id="choices">
<option id="choose_me" value="foobar">blah</option>
<option id="whatever" value="whatever">blah</option>
</select>
<input id="show_me" name="whatever" type="text" value="I am hidden" style="display:none;" />
</form>
I prefer jQuery for all my javascript needs:对于我所有的 javascript 需求,我更喜欢 jQuery:
//jquery
$('#choices').live('change',function()
{
if($('#choose_me').is(':selected'))
{
$('#show_me').show();
}
else
{
if($('#show_me').is(':visible'))
{
$('#show_me').hide();
}
}
});
Here's a working example: http://jsbin.com/eculot/edit这是一个工作示例: http://jsbin.com/eculot/edit
$('#selectBox').change(function() {
var val=$('#selectBox').val();
if(val=="value")
$('#textbox').show();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.