Implementation of this object passed through href and onclick in A tag

Source: Internet
Author: User

In the background management of a blog, you can add an address for a category, but it is difficult to add an onclick event. If you want to pass the current object to a function, you can write the URL as "Javascript: shoControlSidebar (this)". However, the result shows that this is not feasible. The previous parameter passed is an object, however, no other information is available. I want to get innerText, but this does not point to its A tag.

This is different from <a href = "Javascript: shoControlSidebar (this)"> <a href = "javascript: void (0)" onclick = "shoControlSidebar (this)">.

When onclick = "shoControlSidebar (this)" is used, the interpreter packs an anonymous function for it and changes it:
Copy codeThe Code is as follows:
A. onclick = function anonymous ()
{
ShoControlSidebar (this );
}

This refers to the object "a". When using href, this object has nowhere to be indicated because it is an address.
Copy codeThe Code is as follows:
<A href = "javascript: void (0);" onclick = "test (this);"> A tag test </a>

Copy codeThe Code is as follows:
To obtain innerHTML in
If href = "test (this);" does not get the value, and the program exits, href leads to an error.

Copy codeThe Code is as follows:
Function test (obj ){
Alert (obj );
// Js
Alert (obj. innerHTML );
// Jquery
Alert(objects (obj).html ());
}

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.