如何禁用onclick事件 [英] How do I disable the onclick event

查看:204
本文介绍了如何禁用onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用onclick事件?

我尝试过 onclick =this.disabled = true;,但它没有

How do I disable the onclick event?
I've tried onclick="this.disabled=true;", but it doesn't work.

这是一个HTML表:

<table>
  <tr>
     <td onclick="parent.location='home.php'">Available</td>
     <td onclick="parent.location='home.php'">Available</td>
  </tr>
  <tr>
     <td onclick="parent.location='home.php'"><div onclick="this.disabled=true;">Booked</div></td>
     <td onclick="parent.location='home.php'">Available</td>
  </tr>
</table>

使用上面的代码,它仍然是home.php,即使我点击表单元格标记为已预订。

Using the above code it is still going to home.php, even if i click on the table cell marked `Booked'.

推荐答案

您需要防止事件向上冒泡。最简单的方法:

You need to prevent the event from bubbling upwards.. most simple way:

<div onclick="event.cancelBubble = true;">Booked</div>

成功测试IE8,Chrome和Firefox。

Tested successfully for IE8, Chrome and Firefox.

这篇关于如何禁用onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆