Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 如何将jquery克隆脚本中的变量名更改为increment?_Javascript_Php_Jquery - Fatal编程技术网

Javascript 如何将jquery克隆脚本中的变量名更改为increment?

Javascript 如何将jquery克隆脚本中的变量名更改为increment?,javascript,php,jquery,Javascript,Php,Jquery,我想更改变量myAuthorText和mybookText的名称,以保持作者及其书籍与其他作者及其书籍分开 我通常在php中是这样做的: <?php $x = 0; echo " <html> <form action='' method='post'> <input type='text' name='myText.'{$x}'.[]'/> </fo

我想更改变量myAuthorText和mybookText的名称,以保持作者及其书籍与其他作者及其书籍分开

我通常在php中是这样做的:

<?php
$x = 0;
echo "

        <html>
            <form action='' method='post'>
                <input type='text' name='myText.'{$x}'.[]'/>
            </form>
        </html>

    ";

?>

只是一句旁白:永远不要在表单中调用任何东西
name=“submit”
你所说的
到底是什么意思“我想用JQuery来实现这一点,这样我就不必在每次添加新作者或书籍时都重新加载页面。在.clone之后,我想让它更改名称”
。你能详细说明一下吗more@dreamweiver我希望JQuery代码在每个.clone处更改变量名。用户按下“添加作者”按钮后,我希望下一个变量名“myAuthorText[]”将其名称更改为“myAuthorText1[]”您是否可以创建一个JSFIDLE,它在JSFIDLE.net中不起作用,但下面是我在那里做的工作:[
<div class="container">
    <form class="form-horizontal" role="form" action="next.php" method="post">



<!--        http://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery-->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <div class="input_fields_wrap">
            <button class="add_field_button">Add Author</button>

            <div id="commonPart" class="commonPart">
                <br>
            <div><input type="text" name="myAuthorText[]" placeholder="Auth name"></div>

            <button class="add_sub_field_button">Add Author Books</button>
            <div><input type="text" class="bookname" name="myBooksText[]" placeholder="Book name"></div>

             </div>

        </div>
        <input name="submit" class="submit" value="Enviar" type="submit">
<!--        http://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery-->

    </form>
</div>   


    <script src="../js/jquery-2.1.4.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/jqBootstrapValidation.js"></script>
    <SCRIPT language="javascript">

        //http://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery


    $(document).ready(function() {
        var max_fields      = 10; //maximum input boxes allowed
        var wrapper         = $(".input_fields_wrap"); //Fields wrapper
        var commonPart      = $("#commonPart"); 
        var add_button      = $(".add_field_button"); //Add button ID
        var add_subButton   = $(".add_sub_field_button"); //Add sub button ID

        var x = 1; //initlal text box count
        $(add_button).click(function(e){ //on add input button click
            e.preventDefault();
            if(x < max_fields){ //max input box allowed
                var htmlToAdd = commonPart.clone().attr("id","commonPart_"+x);
                htmlToAdd.find(".addedDiv").remove();
                $(wrapper).append(htmlToAdd); //add input box
              x++; //text box increment
            }
        });

        $(document).on("click",".add_sub_field_button",function(e){ //on add input button click
            e.preventDefault();
            if(x < max_fields){ //max input box allowed
                x++; //text box increment
                $(this).closest(".commonPart").append('<div class="addedDiv"><input type="text" class="bookname" name="myBooksText[]" placeholder="Book name"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
            }
        });
        $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
            e.preventDefault(); $(this).parent('div').remove(); x--;
        })
    });

    //http://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery
    </SCRIPT>