Cancel onclick event for one column in table

2019-07-29 04:34发布

问题:

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>