Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 多个收件人的字段_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 多个收件人的字段

Javascript 多个收件人的字段,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想创建一个本身包含其他元素的字段。类似于在社交网络中向多个用户发送消息。 我试图探索代码,但它太混乱了。如果有人能分享他的经验和材料,我将不胜感激 <div class="input_fields_wrap"> <button class="add_field_button">Add Fields</button> <div><input type="text" name="mytext[]"></div> </d

我想创建一个本身包含其他元素的字段。类似于在社交网络中向多个用户发送消息。

我试图探索代码,但它太混乱了。如果有人能分享他的经验和材料,我将不胜感激

<div class="input_fields_wrap">
<button class="add_field_button">Add Fields</button>
<div><input type="text" name="mytext[]"></div>
</div>

$(document).ready(function() {
    var max_fields      = 10; 
    var wrapper         = $(".input_fields_wrap"); 
    var add_button      = $(".add_field_button"); 

    var x = 1;
    $(add_button).click(function(e){ 
        e.preventDefault();
        if(x < max_fields){ 
            x++; 
            $(wrapper).append('<div><input type="text" name="mytext[]"/><a href="#" class="remove_field">Remove</a></div>'); 
        }
    });

    $(wrapper).on("click",".remove_field", function(e){ 
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});

添加字段
$(文档).ready(函数(){
var max_字段=10;
变量包装=$(“.input_fields_wrap”);
var add_button=$(“.add_field_button”);
var x=1;
$(添加按钮)。单击(函数(e){
e、 预防默认值();
如果(x

对于您的案例,我认为它会起作用。您可以在以下网站上找到更多信息:


享受。

你能分享代码吗?你的代码在哪里?你想探索哪些代码?添加代码。我尝试过facebook,但不太奏效。对不起,为什么是cons?你的意思是:@madalinivascu是的,非常感谢你的链接