I have a href
link and I would like it to be clicked when the page is loaded.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
$(document).ready(function() {
$('#someLinkId').click();
});
Or
$(document).ready(function() {
$('#someLinkId').trigger("click");
});
回答2:
$(document).ready(function () {
$("#myLink").trigger('click');
});
as you can read in: http://docs.jquery.com/Events/trigger#eventdata
回答3:
What's the point of loading the page if you're going to navigate away from it immediately?
In addition to jQuery's triggering abilities, you could do:
<body onload="window.location.replace('http://example.com/');">
or:
<body onload="window.location.href = 'http://example.com/';">
回答4:
$("#whateverid").trigger("click");
Where "whateverid" is the ID of the anchor tag, or whatever other selector you want to use.