jquery bind change css

2019-07-09 01:10发布

I'm trying the following:

$('table.table_record_even').bind("contextmenu", function(e) {
    $('#right_menu').css({
        top: e.pageY+'px',
        left: e.pageX+'px'
    }).show();
    return false;

    $(this).css({"background":"#FFFBCC"});

});

When rightclick on the table the css doesn't change. Someone knows how to solve it?

Thnx

EDIT

I've changed the code a little bit and i've made a fiddle to explain a little better. As you can see, with right clicking there is a little problem with remove the hover class.

http://fiddle.jshell.net/9Ku7h/5/

标签: jquery bind
4条回答
Ridiculous、
2楼-- · 2019-07-09 01:39

try:

$('table.table_record_even').bind("contextmenu", function(e) {
    $('#right_menu').css({'position':'absolute',
        "top": e.pageY+'px',
        "left": e.pageX+'px'
    }).show();


    $(this).css({"background":"#FFFBCC"});
    return false;

});
查看更多
手持菜刀,她持情操
3楼-- · 2019-07-09 01:45
$('table.table_record_even').mousedown(function(e) {
    if (e.which === 3) {
        /* Right Mousebutton was clicked! */
        $('#right_menu').css({
           top: e.pageY+'px',
           left: e.pageX+'px'
        }).show();

        $(this).css({"background":"#FFFBCC"});
        return false;
    }
});
查看更多
做自己的国王
4楼-- · 2019-07-09 01:47

You were returning false before processing the css;

    $('table.table_record_even').bind("contextmenu", function(e) {
        $('#right_menu').css({
            top: e.pageY+'px',
            left: e.pageX+'px'
        }).show();


        $(this).css({"background":"#FFFBCC"});
    return false;

    });
查看更多
Melony?
5楼-- · 2019-07-09 01:58

This is because return statement, just move it to the bottom of your function:

$('table.table_record_even').bind("contextmenu", function(e) {
    $('#right_menu').css({
        top: e.pageY+'px',
        left: e.pageX+'px'
    }).show();
    $(this).css({"background":"#FFFBCC"});
    return false;

});
查看更多
登录 后发表回答