jquery on=>keyup無法綁定未來js添加的元素

來源:互聯網
上載者:User

標籤:height   asc   jquer   function   var   this   mod   set   weight   

$("[name=red_count]").on("keyup", countKeyUpBind);即使使用on的,也無法綁定未來元素,所以直接在動態添加的時候,再進行綁定keyup事件 至於click是允許的 同時,對於jquery中before,after添加的標籤,不管是click還是keyup都是沒有綁定未來元素的功能  //紅包個數統計 $("[name=red_count]").on("keyup", countKeyUpBind); //紅包金額統計,keyup不能動態使用的 $("[name=red_money]").on("keyup", moneyKeyUpBind); function countKeyUpBind(){ var count = 0; $("#red_mode_set [name=red_count]").each(function () { var v = parseInt($(this).val()); if(!isNaN(v)){ count += v; } }) $("#red_quantity").html(count + "個"); } function moneyKeyUpBind(){ var amount = 0; $("#red_mode_set [name=red_money]").each(function () { var v = parseFloat($(this).val()); if (!isNaN(v)) { amount += v; } }) $("#red_amount").html(amount + "元"); } //添加紅包模式 $(".drag_ad").click(function () { $("#red_mode_set").append($("#red_mode_template").html()); $("#red_mode_set [name=red_money]:last").bind("keyup", moneyKeyUpBind); $("#red_mode_set [name=red_count]:last").bind("keyup", countKeyUpBind); })  
    //金額統計,keyup不能動態使用的    $("[name=red_money]").on("keyup", moneyKeyUpBind);    function moneyKeyUpBind(){        var amount = 0;        $("#red_mode_set [name=red_money]").each(function () {            var v = parseFloat($(this).val());            if (!isNaN(v)) {                amount += v;            }        })        $("#red_amount").html(amount + "元");    }    //添加紅包模式    $(".drag_ad").click(function () {        $("#red_mode_set").append($("#red_mode_template").html());        $("#red_mode_set [name=red_money]:last").bind("keyup", moneyKeyUpBind);    })

 

jquery on=>keyup無法綁定未來js添加的元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.