代码之家  ›  专栏  ›  技术社区  ›  Simon Price

JQuery click事件需要双击

  •  -1
  • Simon Price  · 技术社区  · 7 年前

    在标记为副本之前,我已经看了以下问题,但没有任何效果。

    jQuery click event requires double click to work

    Click and double-click event firing (松散分布)

    https://jsfiddle.net/SimonPrice/6e9acbo6/5/

    在这张图中,您将看到数据的准确表示,扩展和折叠函数不起作用,因此我从javascript窗口中删除了它们的函数,以避免弹出窗口\警报的干扰。

    使用此代码

    $(document).ready(function () {
    
    $(document).on('click', '.up', function () {
        shiftRow($(this));
    });
    $(document).on('click', '.down', function () {
        shiftRow($(this));
    });
    
    });
    

    我也在document、table、tr和td元素以及类click事件上进行了尝试。

    我需要这个工作在一个单一的点击,如果有人能帮助我看到的错误,我将不胜感激。

    1 回复  |  直到 7 年前
        1
  •  3
  •   Oleg Zlodkov    7 年前

    我为您的函数添加了其他日志:

    function shiftRow(rowbObj) {
    console.log("up or down arrow clicked");
    var row = $(rowbObj).closest("tr");
    console.log(row[0].rowIndex);
    var thisTable = row.closest("table");
    if ($(rowbObj).is(".up")) {
        if (row[0].rowIndex > 0) {
         console.log("current: "+row.text() + " prev: " +row.prev().text());
    

    因此,它帮助我意识到,您有额外的隐藏TR用于行内容(可能用于扩展)(

    <tr id="content_0_36000" class="content" style="display: none;">
    

    )