[英]link trigger on page load is not working
I'm making a simple example on triggering a click on a link on page load but it's not working. 我正在做一个关于在页面加载时触发对链接的单击的简单示例,但是它不起作用。 I don't want to navigate the that href I just want the trigger to work for something else I'll work on here's the head code
我不想浏览那个href,我只想让触发器对我将要处理的其他东西起作用,这是头代码
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"> </script>
<script type="text/javascript">
$(document).ready(function() {
setTimeout(function() {
$("a#test").trigger('click');
},1000);
});
</script>
and the body code 和身体代码
<a href="http://www.yahoo.com" id="test">click</a>
Can you try this, 你可以试试这个吗
$(document).ready(function() {
$( "#test" ).on( "click", function() {
alert('Clicked');
window.location.href = $( this ).attr('href'); //automatic redirection from the link href
console.log('clicked');
});
setTimeout(function() {
$("#test").trigger('click');
},1000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.