Cancel onclick event for one column in table

不想你离开。 提交于 2019-12-11 08:34:48

问题


I've done some digging and been unable to find a solution to this little problem. I have a table where I've made each row clickable using:

<tr class="clickable" onclick="window.document.location='$link';">

I'd like to make this work for all but the last column in the table but all the solutions I've found so far involve jQuery. Is there a way of "cancelling" the row onclick event for one column?

TIA


回答1:


Here is the code - http://jsbin.com/iLISUDu/2/

  <!DOCTYPE html>
  <html>
  <head>
  <meta charset=utf-8 />
  <title>JS Bin</title>
  </head>
  <body>
    <table>
      <tr onclick='window.location.href="google.com";'>
        <td>Hello</td>
        <td>We are cells</td>
        <td onclick='event.stopPropagation();return false;'>Click Me</td>
      </tr>
    </table>
  </body>
  </html>



回答2:


Click events can be cancelled by returning false from the handler event.




回答3:


try

<td onclick="(function(e){e.preventDefault();})">A</td>



来源:https://stackoverflow.com/questions/20494288/cancel-onclick-event-for-one-column-in-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!