我有一個表我使用jQuery UI的「可排序」上。在該表中,我已經由一個「拖動手柄」的行搶,並重新排序表,並與可點擊項目的細胞,就像這樣:jQuery UI排序和生活()點擊問題 - 需要點擊兩次後點擊登記
<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>
在我的代碼,我使表排序,並且還使用jQuery的生活()的點擊事件綁定到可點擊的內容,就像這樣:
$(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"
});
});
我使用的是活的(),因爲行可以動態地添加到表中真正的代碼。
我的問題是:如果我點擊任何可點擊的項目排序之前,他們工作正常。用戶拖動行重新排序後,我必須點擊兩次點擊註冊。在第二次點擊之後,可點擊的項目將回到「正常」,只需點擊一次,直到下一次拖動行。
如果我使用click()而不是live() - 就像在註釋掉的代碼中一樣 - 那麼單擊就可以在任何時候都正常工作,但我寧願使用live(),正如我所說。我很好奇它爲什麼不起作用。
有a live jsFiddle example here。嘗試將行拖入不同的位置,然後單擊任何「測試...」鏈接。在Firefox中,至少,我需要點擊兩次以獲得「成功點擊」警報。
任何想法?
Chrome沒有問題。 – Stephen 2010-11-25 15:51:19
我在FF中驗證了這個問題,但這是一個奇怪的錯誤!除非有人在這裏回答我缺少的內容,否則您可能需要提交錯誤報告。 – Stephen 2010-11-25 15:53:10