单个链接取消链接并触发js事件
复制代码 代码如下:
复制代码
<a href="javascript:void(0);" onclick="alert('ok')">测试</a>
<a href="javascript:void(0);" onclick="alert('ok')">测试</a>
批量将网页中的链接取消或重新设置链接的代码:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
如果想让指定id的链接字取消或恢复链接可以参考下面的代码
复制代码 代码如下:
复制代码
var e=document.getElementById( "link1 ")
//设置
e.setAttribute( "href ",e.rel)
//取消
e.setAttribute( "rel ",e.href)
e.removeAttribute( "href ")
var e=document.getElementById( "link1 ")
//设置
e.setAttribute( "href ",e.rel)
//取消
e.setAttribute( "rel ",e.href)
e.removeAttribute( "href ")
代码说明:为什么取消需要加上e.setAttribute( "rel ",e.href) ,这段代码就是为a增加一个rel熟悉并设置好链接,方便后来的恢复链接。
最后
以上就是无聊香氛最近收集整理的关于js 取消超链接的方法小结的全部内容,更多相关js内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复