簡體   English   中英

單擊彈出選項時如何獲取行ID(使用全局變量獲取ID)?

[英]how to get Id of row when pop up option click (got Id using global variable)?

您能告訴我如何在彈出選項單擊時獲取行ID嗎?當按下“添加”按鈕時動態生成行。在行上有一個圖標“:”,單擊該圖標會顯示彈出屏幕。我單擊“編輯”或其他選項,要顯示它打開的行的ID。我可以獲取編輯事件。但無法獲取ID。 http://jsfiddle.net/4ajeB/5/

function createTestCase(testCaseName, iscreatedFromScript, jsonObject) {
    var id;
    if (typeof ($("#testCaseContainer li:last").attr('id')) == 'undefined') {
        id = "tc_1";
        var index = id.indexOf("_");
        var count = id.substring(index + 1, id.length);
        count = parseInt(count);
        var conunter = count;
    } else {
        id = $("#testCaseContainer li:last").attr('id');
        var index = id.indexOf("_");
        var count = id.substring(index + 1, id.length);
        count = parseInt(count);
        var conunter = count;
        id = id.substring(0, index) + "_" + parseInt(count + 1);
    }
    var html = '<div class="testcaselist_row">' + '<ul>' + '<li id="' + id + '" class="clickTestCaseRow"><a href="#" style="color: #ffffff!important;">' + id + '<i class="icon1 test_h"></i></a></li>' + '</ul></div>';
    $('#testCaseContainer').append(html).enhanceWithin();
}

$('.edit_h').click(function(){

 alert("edit"+$(this).id)   

})

我使用全局變量獲取了ID。不使用變量就可以獲取ID嗎?

只需將ID作為數據添加到.edit_h ,然后在click事件中訪問它click

    ...
    $('.edit_h').data('originalId', id);
    $('#testCaseContainer').append(html).enhanceWithin();
}

$('.edit_h').click(function(){
    alert("edit ID:"+$(this).data('originalId'));
})

更新的小提琴: http : //jsfiddle.net/4ajeB/6/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM