Summary of how js cancels hyperlinks

Source: Internet
Author: User

Unlink a single link and trigger a js event
Copy codeThe Code is as follows:
<A href = "javascript: void (0);" onclick = "alert ('OK')"> test </a>

Code for canceling links in multiple webpages or resetting links:
Download the software material from the Baidu script home server webmaster query script <input type = button id = o1 value = "cancel all links" onclick = "javascript: doLinkAll (false) "> <input type = button id = o2 value =" Reset link "onclick =" javascript: doLinkAll (true) "> <script> function doLinkAll (action) {var arr = document. getElementsByTagName ("A") for (var I = 0; I
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
If you want to cancel or restore the link of the specified id, refer to the following code:
Copy codeThe Code is as follows:
Var e = document. getElementById ("link1 ")
// Set
E. setAttribute ("href", e. rel)
// Cancel
E. setAttribute ("rel", e. href)
E. removeAttribute ("href ")

Code Description: Why do I need to add e. setAttribute ("rel", e. href) to cancel the cancellation? This Code adds a rel for a and sets a link to facilitate later link recovery.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.