简体   繁体   English

添加多个文本框并通过单击按钮下拉

[英]add multiple text boxes and drop down by click button

$(document).ready(function() {

//To add new input file field dynamically, on click of "Add More Files" button below function will be executed
    $('#add_more').click(function() {
        $(this).before($("<div/>", {id: 'filediv'}).fadeIn('slow').append(

                $("<input/>", {name: 'text[]', type: 'text', id: 'filediv'}), 
                $("<select/>", {name: 'option[]', type: 'option', id: 'filediv'}).append('<option>select</option>','<option value="1">Yes</option>','<option value="2">No</option>'),
                $("<input/>", {name: 'text[]', type: 'text', id: 'filediv'}),  

                $("<br/><br/>")
                ));
    });

I have used this script to add multiple text boxes but the problem is we want last text box while choosing NO option other wise it should be disable 我已经使用此脚本添加了多个文本框,但问题是我们希望最后一个文本框同时选择“否”选项,否则应将其禁用

you can try like: 您可以尝试:

$('#add_more').prev().remove('<div/>');

If your code is using .append(), one option would be to keep a reference to the element you're appending, and use that to remove it later. 如果您的代码使用.append(),则一种选择是保留对要添加的元素的引用,并使用该引用稍后将其删除。

var $appendElem = $('<div>some appended element</div>');

$appendElem.appendTo('#add_more');

Then you can remove it via the same reference. 然后,您可以通过相同的引用将其删除。

$appendElem.remove();
// or
$appendElem.detach();​​​​​​​​​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM