2016-09-20 170 views
6

右鍵菜單正確地與其功能配合使用。 但問題是有時它不能正常工作。 在我看來,如果右鍵單擊表格行正確選中了該複選框,但在取消選中後,再次嘗試使用右鍵單擊它不起作用。右鍵單擊自定義菜單無法正常工作

$('.check').bind("contextmenu", function (event) { 
    event.preventDefault(); 

    $(".custom-menu").finish().toggle(100).css({ 
     top: event.pageY + "px", 
     left: event.pageX + "px" 
    }); 
}); 


$(document).bind("mousedown", function (e) { 
    if (!$(e.target).parents(".custom-menu").length > 0) { 
     $(".custom-menu").hide(100); 
    } 
}); 


$('tr.check').contextmenu(function (e) { 
    $cb = $(this).find('input[type="checkbox"].selected_check'); 
    $($cb).attr('checked', 'checked'); 
    populate_context_menu($cb); 

    return false; 
}); 
+1

嗨@menaka,你可以添加jsFiddle鏈接或其他東西,所以它會更容易回答! – Ranj

+2

@ Rj_01:對不起,我沒有使用jsFiddle或其他。 –

+0

好的,我會試試。謝謝男人。 –

回答

2

我用一些代碼行改變了我的代碼,它對我有幫助。

$(".custom-menu li").click(function() { 

    $(".custom-menu").hide(100); 
}); 

function isExist(id) { 
    for (var i = 0; i < values.length; i++) { 
    if (values[i] == id) { 
     return true; 
    } 
} 
    return false; 
} 

$('tr.check').contextmenu(function (e) { 

    $cb = $(this).find('input[type="checkbox"].selected_check'); 
     var id = $($cb).attr('id'); 
     var result = isExist(id); 

     if (!result) { 
      $('.selected_check').attr('checked', false); 
      $('.check').removeClass('highlight_row'); 
      $('.check').addClass('td_bgcolor'); 
     } 

     $($cb).attr('checked', 'checked'); 

     populate_context_menu($cb); 

      return false; 
     });