jquery添加的html元素按鈕爲何不執行類樣式綁定的click事件

問題:在作頁面的時候,有不少時候許多按鈕還有許多行是須要動態生成的,可是動態生成以後點擊按鈕或者刪除,沒法觸發綁定的click事件。編程

解決:在添加更多一行的時候所產生的 input 和 button 都是動態生成的,因此不能使用 click,要使用 onide

把$(".submitBtn").click(function(){
$(document).on('click','.edit',function(){        $(".modal,.shadow").removeClass('hide');//        this 當前點擊的標籤,parent父標籤,prevAll父標籤上面的全部同級標籤        var tds = $(this).parent().prevAll();//        循環獲取tds中的內容(td中的內容),賦值給編程框中的value        tds.each(function(){//            this 當前每一個td//            獲取自定義屬性的值,hostname/port            var n = $(this).attr('target');//            獲取當前td內容:1.1.1.1/80            var v = $(this).text();//            將獲取的內容放入相應的編程框中//          $('.modal input[name="[hostname"]').val(1.1.1.1)//            由於hostaname/port爲變量,而name=裏面須要是「」格式,因此用到字符串拼接//            var a1 = '.modal input[name="';//            var a2 = '"]';//            var temp = a1 + n + a2            $('.modal input[name="' + n + '"]').val(v)        });    });
相關文章
相關標籤/搜索