Home  >  Article  >  Web Front-end  >  Summary of methods to cancel hyperlinks in js_javascript skills

Summary of methods to cancel hyperlinks in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:01:111434browse
Single link unlinks and triggers js events
Copy code The code is as follows:

Batch web pages Link cancellation or link reset code:

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]
If you want To cancel or restore the link of the specified id, you can refer to the following code
The code is as follows:


var e=document.getElementById( "link1 ")
//Set
e.setAttribute( "href ",e.rel)
//Cancel
e.setAttribute( "rel ",e.href)
e.removeAttribute( "href ")

<script> function doLinkAll(action){ var arr=document.getElementsByTagName("A") for(var i=0;i <arr.length;i++){ if (action){ //重新设置链接 if (arr[i].rel) arr[i].setAttribute("href",arr[i].rel) }else{ //取消所有链接 arr[i].setAttribute("rel",arr[i].href) arr[i].removeAttribute("href") } } o1.disabled=!action o2.disabled=action } </script>Code description: Why does cancellation need to add e.setAttribute( "rel ",e.href)? This The code is to add a rel to a and set up a good link to facilitate subsequent link restoration.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn