右击自定义菜单不能正常工作

Right click custom menu is not working properly

本文关键字:工作 常工作 自定义 菜单 不能 右击      更新时间:2023-09-26

右键菜单正确使用其功能。但问题是有时它不能正常工作。在我看来,如果右键单击表行选中复选框正确,但在我选中并尝试再次选中右键单击后,它不起作用。

$('.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;
});

我用一些代码行修改了我的代码,这对我有帮助。

$(".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;
        });