选择选项时添加输入文本 [英] Add input text when option selected

查看:102
本文介绍了选择选项时添加输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加一个时之间的特定选项标签被选中,然后,如果选择了另一种选择,使用jQuery删除文本字段?

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();
    }
});

生活示例: http://jsfiddle.net/MKPdb/

这篇关于选择选项时添加输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆