a tag self-executing click event

//html 

  <a href='http://www.baidu.com'><button id='sss'>百度</button></a>

// Native js

function trigger(){

//IE

    if(document.all) {

        document.getElementById("clickMe").click();

    }

// other browsers

    else {

        var e = document.createEvent("MouseEvents");

        e.initEvent( "click", true, true);              //The click here can be replaced with the behavior you want to trigger

            document.getElementById( "sss").dispatchEvent(e);   //clickME here can be replaced with the DOM node you want to trigger the action

        }   

}

 

trigger()

//jq

$('#sss').trigger('click')

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325053694&siteId=291194637