In the blog background management, it is allowed to add an address to a category, but it is difficult to add the onclick event. I want to pass the current object to a function, so I wrote the URL as "Javascript:shoControlSidebar(this)", but it turned out that this was not feasible. The passed parameter was an object, but I could not get any other information. What I want is innerText, and this this does not point to the A tag where it is located.
This is the difference between <a href="Javascript:shoControlSidebar(this)"> and <a href="javascript:void(0)" onclick="shoControlSidebar(this)">.
When using onclick="shoControlSidebar(this)", the interpreter will wrap an anonymous function to it and become:
= function anonymous()
{
shoControlSidebar(this);
}
This this refers to the object a, and when using the href method, since it is an address, this this has nowhere to refer to.
<a href="javascript:void(0);" onclick="test(this);">A tag test</a>
Want to get innerHTML in A
If href="test(this);" not only does not get the value, but the program will exit, and the href leads incorrectly.
function test(obj){
alert(obj);
//js
alert();
//jquery
alert($(obj).html());
}
This is the difference between <a href="Javascript:shoControlSidebar(this)"> and <a href="javascript:void(0)" onclick="shoControlSidebar(this)">.
When using onclick="shoControlSidebar(this)", the interpreter will wrap an anonymous function to it and become:
Copy the codeThe code is as follows:
= function anonymous()
{
shoControlSidebar(this);
}
This this refers to the object a, and when using the href method, since it is an address, this this has nowhere to refer to.
Copy the codeThe code is as follows:
<a href="javascript:void(0);" onclick="test(this);">A tag test</a>
Copy the codeThe code is as follows:
Want to get innerHTML in A
If href="test(this);" not only does not get the value, but the program will exit, and the href leads incorrectly.
Copy the codeThe code is as follows:
function test(obj){
alert(obj);
//js
alert();
//jquery
alert($(obj).html());
}