$('a').trigger('click'); not working

后端 未结 9 2401
南旧
南旧 2021-02-19 04:06

How do I make jquery click test



        
9条回答
  •  情书的邮戳
    2021-02-19 04:45

    You need to trigger the default click method, not the one by jQuery. This can be done by adding the default click option within a click event of jQuery using this.

    
    

    This is how the JavaScript looks. It basically creates the event when the DOM is ready, and clicks it intermediately, thus following the link.

    $(function() {
        $('a').click(function() {
            // 'this' is not a jQuery object, so it will use
            // the default click() function
            this.click();
        }).click();
    });
    

    To see a live example (opening about.com), see: http://jsfiddle.net/8H9UX/

提交回复
热议问题