Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery UI sortable and live()单击问题--排序后需要单击两次才能注册单击_Jquery_Jquery Ui_Jquery Ui Sortable - Fatal编程技术网

jQuery UI sortable and live()单击问题--排序后需要单击两次才能注册单击

jQuery UI sortable and live()单击问题--排序后需要单击两次才能注册单击,jquery,jquery-ui,jquery-ui-sortable,Jquery,Jquery Ui,Jquery Ui Sortable,我有一个使用jQueryUI的“sortable”的表。在表中,我有由一个“拖动手柄”组成的行,用于抓取和重新排序表,以及带有可单击项的单元格,如下所示: <table id="test-table"> <tbody> <tr> <td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td> &l

我有一个使用jQueryUI的“sortable”的表。在表中,我有由一个“拖动手柄”组成的行,用于抓取和重新排序表,以及带有可单击项的单元格,如下所示:

<table id="test-table">
    <tbody>
    <tr>
        <td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td>
        <td class="clickycell"><a href="#">Testing 1</a></td>
    </tr>
    <tr>
        <td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td>
        <td class="clickycell"><a href="#">Testing 2</a></td></td>
    <tr>
        <td class="handle"><div class="ui-icon ui-icon-arrowthick-2-n-s" /></td>
        <td class="clickycell"><a href="#">Testing 3</a></td></td>
    </tr>
    </tbody>
</table>
$(function() {
    /*
       Using live() because in my real code table rows are dynamically added.
       However, if I use click() instead, as in the commented-out code, it works
       fine, without any need to click twice.

    */
    // $(".clickycell a").click(function() {
    $(".clickycell a").live('click', function() {
        alert("Successful click");
        return false;
    });
    $("#test-table tbody").sortable({
        handle: "td.handle", /* Use the draggy handle to move, not the whole row */
        cursor: "move"
    });
});
我使用的是
live()
,因为行可以在实际代码中动态添加到表中

我的问题是:如果我在排序之前单击任何可单击的项目,它们都可以正常工作。但是,在用户拖动行以对其进行重新排序之后,我必须单击两次才能注册。在第二次单击之后,可单击的项目返回“正常”,只需单击一次,直到下一次拖动行为止

如果我使用
click()
而不是
live()
——就像在注释掉的代码中一样——那么一次单击在任何时候都可以正常工作,但正如我所说,我宁愿使用
live()
。我很好奇为什么它不起作用

有一个。尝试将一行拖动到其他位置,然后单击任何“测试…”链接。至少在Firefox中,我需要点击两次以获得“成功点击”警报


有什么想法吗?

不幸的是,最后的答案是“但我想有时候会发生这种情况。也许我会掸掉我的GitHub登录名的灰尘,然后用叉子叉一下,看看我是否能找到它并找到修复方法。

当我找到你的帖子时,我对“live”和sortable也有同样的问题(代理也有同样的问题)。为了跟进@Stephen关于在与live works绑定的项目单击处理程序之前单击一次拖动手柄而不必单击两次的观察结果。。。我已经成功地使用了这个变通方法。作为一个黑客,我不觉得它太无礼

$('table.demo tbody').sortable({
    handle: 'td.drag',
    stop: function(e,ui){
        $('td.drag', ui.item).click();
    }
});

我只是在拖动完成后向拖动处理程序发出一个单击调用,现在我与live绑定的其他项目(在我的行中)不需要单击两次。

Chrome没有问题。我在FF中验证了这个问题,但这是一个奇怪的错误!除非有人在这里回答我缺少的东西,否则你可能想提交一份bug报告。@Stephen有趣,谢谢;可能确实是一个jQuery错误。这个问题也出现在IE6上,它是我工作时唯一可用的浏览器(不要问!)。有趣的是,在我完成拖动后,我可以单击一次拖动手柄,然后单击链接,它就可以工作了。因此,似乎单击事件冒泡或其他问题存在。我猜这是jQueryUI处理.live方法的一个bug,而不是jQuery。@Stephen已经玩过了,现在明白你说的.children('a')是什么意思了。奇怪的是.find('a')起作用,而且.children('a')除了live()外,对任何东西都起作用。。。我现在头疼!恐怕我无法验证这一点,因为我现在已经转到另一个方面,但是+1用于添加答案;希望它能帮助别人!