使用JavaScript禁用onClick功能 [英] Disable onClick functionality using JavaScript

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

问题描述

我正在为图像使用onClick事件。

I am using onClick event for the image.

当我对特定情况禁用时,我不确切知道如何禁用 onClick 使用JavaScript的功能。

When I am disable for the particular case, I didn't know exactly how can disable the onClick functionality using JavaScript.

示例代码:

<td>
    <a onClick="fun()">
        <html:img src="/caleder.jpg ... />
    </a>
</td>

调用乐趣:

function fun() {
    // in fun I want to disable the img and onClick functionality
    // i.e when I click that img, then it can't perform the onClick event.
}


推荐答案

自删除事件监听器以来最有效的方法:

The probably most efficient way since it removes the event listener:

<script>
  function fun(node) {
    document.getElementById(node).removeAttribute("onClick");
  }
</script>

onClick()你需要放置这个所以它将是 onClick(this)

Inside of the onClick() you need to place a this so it would be onClick(this)

这篇关于使用JavaScript禁用onClick功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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