Analysis of $.click () invalidation problem in jquery

Source: Internet
Author: User

Today, when the table is exported to XLS, you want to automatically trigger a click. but failed. Finally find this file.

I tried many times to use jquery to simulate the user's ability to click on a tag, but it didn't work and it bothered for a long time. A moment ago, a daze, out of a new idea, so the hands of the test.

First look at the following code:

The

code is as follows:


<html>


<head> Grinding Song-a label test 1<head>


<body>


<a href= "http://blog.mo2g.com" > Grinding song <a>


</body>


</html>


<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ><script>


<script>


JQuery (function ($) {


//To all a tags to bind fixed-point hit trigger event


$ (' a '). Click (function () {


alert (1);


});


//Trigger Click event for all a tags


$ (' a '). Click ();


});


</script>

The code above really has triggered the click a tag event, but everyone will also have a question, why click on a tag, but not trigger a label jump event?

At first it was thought that the browser did the corresponding security measures, shielding the JS to a label operation, and later found that this is not the case, then say the whole story.

Before I start to explain, I'm going to throw a question. When we click on "a tag", what exactly is clicked to jump?

1 Click on the "a tag" itself?

2 Click on the "a label" in the text displayed?

Speaking of which, we should understand that the code above has confirmed that clicking on the a tag itself does not trigger the event that jumps to the specified link, that is, we usually click on the text in the a tag.

Now that you have a clue, try it.

The

code is as follows:


<html>


<head> Grinding Song-a label test 2<head>


<body>


<a href= "http://www.mo2g.com" > Grinding song <a>


</body>


</html>


<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ><script>


<script>


JQuery (function ($) {


var mo2g = ' <span id= ' mo2g ' > Mill extension City <span> ';


//Add an element to the text in label A that can be captured by jquery


$ (' a '). Append (mo2g);


//Analog Click on the text in a label


$ (' #mo2g '). Click ();


});


</script>

The effect came out, the facts proved that the above inference is correct, so to use JS analog click a tag event, you have to go to a label in the text to add can be JS capture elements, and then use JS analog click on the element can be.

These are the relevant jquery $ ("a") in this article. Click () Invalid problem analysis, I hope that the small partners can enjoy.

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.