zoukankan      html  css  js  c++  java
  • 点击按钮添加一组下拉框,然后改变下拉框的值触发事件

    帮朋友做的一个简单特效。一般情况下,用js插入标签,普通的触发事件对它是无效的,但是可以换种写法就行啦。

    直接上代码啦,简单的东西

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
    </head>
    <body>
    
        <div class="sellect_box" style="margin:0 auto;300px;">
            <select class="select1">
                <option value=""></option>
                <option value="2">2</option>
                <option value="3">3</option>
            </select>
            <!--<select class="select2">
                <option>操作1</option>
                <option>操作2</option>
                <option>操作3</option>
            </select>-->
            <button class="btn">添加</button>
        </div>
    
        <script>
            $(document).on("change",".sellect_box .select1",function(){
                //第二个下拉框,根据第一个下拉框,填入对应的数据
                    var sel="<select class="select2">"+
                            "            <option>操作1</option>"+
                            "            <option>操作2</option>"+
                            "            <option>操作3</option>"+
                            "        </select>";
                $(this).after(sel);
            })
            
            
            //点击添加,再添加一行
            $(document).on("click",".btn",function(){
                
                var selHtml="<div class="sellect_box" style="margin:0 auto;300px;">"+
                        "        <select class="select1">"+
                        "            <option value=""></option>"+
                        "            <option value="2">2</option>"+
                        "            <option value="3">3</option>"+
                        "        </select>"+
                        "        <button class="btn">添加</button>"+
                        "    </div>";
            
                $(this).parent(".sellect_box").after(selHtml);
            })
        </script>
    </body>
    </html>
  • 相关阅读:
    UVA 12307 Smallest Enclosing Rectangle
    UVALive 4728 Squares
    扩栈代码
    uva 10256 The Great Divide
    uva 11168 Airport
    uva 10625 Board Wrapping
    bzoj千题计划206:bzoj1076: [SCOI2008]奖励关
    NOIP2017 列队
    bzoj3529: [Sdoi2014]数表
    bzoj1966: [Ahoi2005]VIRUS 病毒检测
  • 原文地址:https://www.cnblogs.com/LChenglong/p/7089376.html
Copyright © 2011-2022 走看看