在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ jquery如何獲取當(dāng)前點(diǎn)擊按鈕所在的行,然后刪除

jquery如何獲取當(dāng)前點(diǎn)擊按鈕所在的行,然后刪除

使用datatable,我想要點(diǎn)擊刪除按鈕刪除當(dāng)前所在行,但是我按如下方式刪除的時候,獲取到的DOM元素只有第一次是當(dāng)前行,多點(diǎn)擊幾次之后就是把其他行的DOM也獲取到了,如何只是獲取到當(dāng)前行。

t.row($(e).parents('tr')).remove().draw(false);

clipboard.png
這是代碼結(jié)構(gòu)

function removeStatus(e,tableId) {
    $("deleteModal .modal-body p").html("確認(rèn)刪除該條數(shù)據(jù)嗎?");
    $("#deleteModal"). modal();
    $("#delete").click(function () {
        $("#deleteModal"). modal('hide');
        deleteTr(e);
        for(let s of statusList){
            if(s['tableId']===tableId){
                statusList.remove(s)
            }
        }
    })
}
function deleteTr(e){
    console.log($(e).parent('td').parent("tr").find("td:first-child").html())
    t.row($(e).parents('tr')).remove().draw(false);
}

clipboard.png
點(diǎn)擊一次刪除按鈕就會console出多個行的值甚至多次console.

問題應(yīng)該在

$("#delete").click(function () {
        $("#deleteModal"). modal('hide');
        deleteTr(e);
        for(let s of statusList){
            if(s['tableId']===tableId){
                statusList.remove(s)
            }
        }
    })

這個點(diǎn)擊事件里,如果是在這個事件之外,一點(diǎn)問題沒有,如果寫在這個事件里就會這樣。

回答
編輯回答
苦妄

事件重復(fù)綁定。沒運(yùn)行一次removeStatus函數(shù),$("#delete").click就被綁定一次,可以把這個事件綁定的代碼放到外面,或者先解綁

$("#delete").unbind('click').click()
2017年8月18日 16:27
編輯回答
哎呦喂

你的click事件重復(fù)綁定了,你每次觸發(fā)removeStatus就給$("#delete")綁定了一次click,觸發(fā)的越多,click就越多,而不會覆蓋上次的,所以你得
$("#delete").unbind("click").click(xxxxx)

2018年8月18日 04:56