In one case, two aspects are simulated: click a super connection event.
Firefox compatible Functions
Add an onclick event to htmlanchorelement
CopyCode The Code is as follows: Try {
// Create a element so that htmlanchorelement is accessible
Document. createelement ('A ');
Htmlelement. Prototype. Click = function (){
If (typeof this. onclick = 'function '){
If (this. onclick ({type: 'click'}) & this. href)
Window. Open (this. href, this.tar get? This.tar get: '_ Self ');
}
Else if (this. href)
Window. Open (this. href, this.tar get? This.tar get: '_ Self ');
};
}
Catch (e ){
// Alert ('click Method for htmlanchorelement couldn \'t be added ');
}
The following are specific applications:
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]
if it is an ordinary HTML add click
This section makes Firefox's htmlelement have the click method (add click method to htmlelement in Mozilla) copy Code the code is as follows: try {
// create span element so that htmlelement is accessible
document. createelement ('span ');
htmlelement. prototype. click = function () {
If (typeof this. onclick = 'function')
This. onclick ({type: 'click'});
};
}< br> catch (E) {
// alert ('click Method for htmlelement couldn \'t be added');
}
The following are other related articles .
recently, it was found that the user press enter in the webpage input box is not fixed...
especially when there are multiple forms on the webpage
I searched for a JS with a simulated click, copy Code the code is as follows: function doclick (linkid, e) {
If (E. keycode! = 13) {
return;
}< br> var fireonthis = document. getelementbyid (linkid)
If (document. createevent)
{< br> var evobj = document. createevent ('mouseevents')
evobj. initevent ('click', true, false)
fireonthis. dispatchevent (evobj)
}< br> else if (document. createeventobject)
{< br> fireonthis. fireevent ('onclick')
}< BR >}
E is an event, built-in object, and linkid is the ID of the simulated clicked object
for example,
in this way, you can press enter to submit the form ~
change opera to copy Code the code is as follows:
click me