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

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

How do I make jquery click test



        
相关标签:
9条回答
  • 2021-02-19 05:03

    Just click:

    $("#mylink").click();
    

    If your scripts are in the head then you need to ensure that the element exists, so the script should be executed when document is ready.

    $(document).ready(function () {
        $("#mylink").click();
    });
    
    0 讨论(0)
  • 2021-02-19 05:07

    your above code will not work because you have assigned value in href and then you want some operation onclick of this anchor tag.

    <a href="test.zip" id="mylink">test</a>
    

    first of all you have assigned .zip to href. So it will open zip file onclick first and will not trigger any other operation in onclick trigger.

    so whatever operation you want to do , perform it first then open .zip

    use code like below

    <a href="javascript:void(0);" id="mylink">test</a>
    
    $('#mylink').click(function(){
        // do your operation here
        // now open zip 
    });
    
    0 讨论(0)
  • 2021-02-19 05:10

    If your intention is to navigate to the specified URL as if the user had clicked the link try calling the DOM .click() method instead of the jQuery .click() method:

    $('#mylink')[0].click();
    

    The jQuery .click() will call event handlers that you've bound but not cause the default click behaviour.

    0 讨论(0)
提交回复
热议问题