mouseup上的JQuery类检查

mouseup上的JQuery类检查,jquery,drupal-7,draggable,Jquery,Drupal 7,Draggable,我有下面的代码,它在检测mousedown和mouseup时起作用。 问题从mouseup开始,我试图检查目标元素是否有特定的类 if语句中的代码从不执行 $(this).find('td:first a.tabledrag-handle').mousedown( function(){ $(this).mouseup( function(){ console.log('mouseup detected');

我有下面的代码,它在检测mousedown和mouseup时起作用。 问题从mouseup开始,我试图检查目标元素是否有特定的类

if语句中的代码从不执行

$(this).find('td:first a.tabledrag-handle').mousedown(
    function(){

        $(this).mouseup(
            function(){
                console.log('mouseup detected');

                $(this).parents('tr').css('background', 'red');

                if( $(this).parents('tr').hasClass('drag-previous') ){
                    console.log('Dragged');
                    $(this).parents('tr').css('background', 'blue');
                }
            }
        );
    }
);
if($(this.parents('tr').hasClass('drag-previous'))。。。代码从不执行

$(this).find('td:first a.tabledrag-handle').mousedown(
    function(){

        $(this).mouseup(
            function(){
                console.log('mouseup detected');

                $(this).parents('tr').css('background', 'red');

                if( $(this).parents('tr').hasClass('drag-previous') ){
                    console.log('Dragged');
                    $(this).parents('tr').css('background', 'blue');
                }
            }
        );
    }
);
请问,有人能提出更好的方法或解决这个问题吗

更新:

我试图实现的是在下表中检测拖放事件。我需要读取通过拖动生成的每行的重量,并在“自定义重量”字段中设置该数字,然后保存自定义重量

这需要为每一行执行,这就是为什么我在十字准线上检测mousedown和mouseup,而不是在mousein上或在行上检测mouseenter和mouseleave事件。

使用mouseenter和mouseleave事件
您可以直接绑定mouseup事件。不必把鼠标放在下面

$("td:first a.tabledrag-handle").mouseup(function (e) {
            $(this).parents("tr").css('background', 'red');
            if ($(this).parents("tr").hasClass('drag-previous')) {
                console.log('Dragged');
                $(this).parents('tr').css('background', 'blue');
            }
        });

如果要检查每行中的td,请按如下方式更改选择器

$("tr td:first-child").mouseup(function (e) {
                $(this).parents("tr").css('background', 'red');
            if ($(this).parents("tr").hasClass('drag-previous')) {
                console.log('Dragged');
                $(this).parents('tr').css('background', 'blue');
            }
        });

发布您的HTML,或提供jsfiddle.netwe您为什么要在mousedown中委派mouseup?@Anton:我正在尝试检测由不同脚本提供的拖放事件,最好为其创建bool变量或数据属性。否则,每次你在同一个元素上下鼠标时,它都会创建多个mouseup函数。谢谢你的回答,但我已经在更新中解释了为什么这不起作用。谢谢,但是我尝试了你的方法,但它不起作用。我在更新我的问题时提供了进一步的细节。