【问题标题】:Why is my html table ignoring clicks?为什么我的 html 表格忽略点击?
【发布时间】:2016-09-16 05:33:28
【问题描述】:

我有一个像这样的 html 表格:

<table id="top10ItemsTable">
    <tr>
        <th>Item Code</th>
        <th>Description</th>
        <th class="rightjustifytext">Qty</th>
    </tr>
    . . .

我想响应该表格内的点击,因此将其添加到就绪函数中:

$("body").on("click", "#top10ItemsTable", function () {
    alert('you clicked inside the Top 10 Items quadrant table');
});

...但是单击 html 表格不会产生任何警报,除非它是微观的或不可见的。

需要什么东西才能用力戳桌子以清除皮屑?

【问题讨论】:

标签: javascript jquery html html-table


【解决方案1】:

你可以这样做:

$("#top10ItemsTable").click(function () {
     alert('you clicked inside the Top 10 Items quadrant table');
}

【讨论】:

    【解决方案2】:

    试试这个:

    $(document).on("click", "#top10ItemsTable", function () {
    
        alert('you clicked inside the Top 10 Items quadrant table');
    
    })
    

    最终代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    </head>
        <body>
          <table id="top10ItemsTable">
        <tr>
            <th>Item Code</th>
            <th>Description</th>
            <th class="rightjustifytext">Qty</th>
        </tr>
            </table>
            
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
           <script>
               
    
        
    $(document).on("click", "#top10ItemsTable", function () {
        
        alert('you clicked inside the Top 10 Items quadrant table');
            
    })     
           </script>
        </body>
    </html>

    【讨论】:

      猜你喜欢
      • 2011-10-05
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2020-11-07
      • 1970-01-01
      • 2020-04-21
      • 2012-10-04
      相关资源
      最近更新 更多