简体   繁体   中英

Trigger OnClick in anchor tag

How can i use trigger() in jquery to emulate onclick attribute of a anchor tag:

<a id="anc" href="#" onclick="someFunction()"> some text </a>

here if i use

$("anc").trigger('click');

its not working

你需要使用#:在jQuery选择器中正确引用id“anc”:

$("#anc").trigger('click');

you need to use # for id

$("#anc").click(function() {
    return false // this will kill the default behaviour and your page won't jump
});

使用id时你可以使用('#idname').trigger('click') ,当你使用你可以使用的类('.classname').trigger)('click')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM