多级嵌套按钮

时间:2017-02-21 16:47:57

标签: javascript jquery html

我意识到这段代码有很多问题阻止了我的目标。所以这是我的目标。我想有一个动态表单,可以添加嵌套元素,最好没有限制级别,但至少约9级。我希望用户在启动时看到一个按钮,并且能够添加项目,然后在每个项目下面添加各种项目,但随后添加另一个相同类型的组。我希望附加的按钮能够附加下一级别的深度。我想根据需要为添加的不同项添加表单字段。所以,简单地说:

  1. 多级嵌套按钮
  2. 每个按钮或部分(按钮和字段)都是可移动的
  3. 如果您有其他问题,请与我们联系。我似乎无法格式化这个以使嵌套和可更改的部分。谢谢你的帮助!

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    
    
    
    </head>
    <body>
    
    <script type="text/javascript">
    $(document).ready(function(){
        $("#btn1").click(function(){
            $("ol").append(" <b>New Item</b>.");
        });
    
        $("#btn2").on("click", function(){
            $("ol").append("<li>New Item Title</li><input type='text'><br /><button id='btn1'>Add Nested Item</button><br /><br />");
        });
    
    
    });
    </script>
    
    <script type="text/javascript">
    
    
    var counter = 0;
    
    $("button").click(function() {
        $("h2").append("<p class='test'>click me " + (++counter) + "</p>")
    });
    
    // With on():
    
    $("h2").on("click", "p.test", function(){
        alert($(this).text());
    });
    
    
    </script>
    
    
    <button id="btn2">Add Item</button>
    
    
    
    <form>
    <ol>
    
    </ol>
    </form>
    
    </body>
    </html>
    

0 个答案:

没有答案