jQuery is mousedown on mouseover

偶尔善良 提交于 2019-12-05 08:26:17

EDIT: Given your comment above, you could do something like this:

$(document).ready(function() {
    isMouseDown = false

    $('body').mousedown(function() {
        isMouseDown = true;
    })
    .mouseup(function() {
        isMouseDown = false;
    });

    $('Table1 tr td').mouseenter(function() {
        if(isMouseDown)
            $(this).css({backgroundColor:'orange'});
    });
});

This will color the background of the td when you mouseover, but only if the mouse button is down.


Sounds like you just want to change the color when you click. If that's the case, it is much simpler than what you're attempting.

$(document).ready() {

    $('#Table1 tr td').click(function() {
        $(this).css({backgroundColor:'yellow'});
    });

});

This will change the background of the td elements yellow when you click them.

It will be similar to change the color when you mouseover.

EDIT: Just noticed the title of your question.

If you want to trigger a click when you hover...

$(document).ready() {

    $('#Table1 tr td').click(function() {
        $(this).css({backgroundColor:'yellow'});
    })
     .mouseenter(function() {
         $(this).click();
     });

});

...of course, you could eliminate the click in that case and just change the background with the mouseenter event.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!