选择选项时添加输入文本
问题描述:
我如何添加一个
How can I add an an <input type="text">
when a specific option between <select></select>
tags is selected, then, if another option is selected, delete that text field using jQuery?
答
您应使用change
事件.然后,您可以比较要为其创建输入的值,并将其添加到body
或任何其他元素中.
You should make use of change
event. Then you could compare the value for which you want to create the input and add it to the body
or to any other element.
生活示例: http://jsfiddle.net/MKPdb/
具有这样的列表,其ID为mylist
,例如:
Having a list like this, with the id mylist
, for example:
<select id="mylist">
...
</select>
您可以使用:
$('#mylist').change(function(){
if( $(this).val() == '1'){
$('body').append('<input id="myInput" type="text" />');
}else{
$('#myInput').remove();
}
});