javascript 在页面加载时自动点击超链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16683648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatically clicking a hyperlink on page load
提问by Phanimadhavi Vasantala
I have a hyperlink in my jsp. When we click on this, a popup overlay gets displayed and the background greys out. After closing the popup, the background becomes normal. Now I want the hyperlink to be clicked automatically when the page loads. Can anyone say how we can do that?
我的jsp中有一个超链接。当我们点击它时,会显示一个弹出叠加层,背景变灰。关闭弹窗后,背景就正常了。现在我希望在页面加载时自动点击超链接。谁能说我们怎么能做到这一点?
I tried the following..
我尝试了以下..
$('#ViewOutages').click(); ,
$('#ViewOutages').click();
but none of it worked.. ViewOutagesis the div id in which the hyperlink is present.
但没有一个工作......ViewOutages是超链接所在的div id。
Can someone please help on this.
有人可以帮忙解决这个问题。
回答by bipen
use trigger()
利用 trigger()
$(function(){
$('#ViewOutages').trigger('click');
})
from
从
'ViewOutages' is the div id in which the hyperlink is present.
'ViewOutages' 是超链接所在的 div id。
looks like your <a>is inside the div ..i assume you need to use find()or children()
看起来你<a>在 div 里面..我假设你需要使用find()或children()
$(function(){
$('#ViewOutages').find('#linkID').trigger('click');
})
回答by Vishal Suthar
Here you go:
干得好:
$(document).ready(function() {
$("#ViewOutages").trigger('click');
}
回答by Phanimadhavi Vasantala
window.onload=function(){
if(document.getElementById('test')!=null||document.getElementById('test')!=""){
document.getElementById('test').click();
}
}
This actually worked.. :)
这实际上有效.. :)
回答by Rohan Kumar
Try this,
试试这个,
$(function(){
$('#ViewOutages').find('a').trigger('click');
// if hyperlink is in div#ViewOutages as you said in question
})
回答by Jay Thakkar
You can use $(document).ready(); function which is same as
您可以使用 $(document).ready(); 功能与

