JavaScript运行完整的A href命令
我有一个网站,那里有一个充满链接的侧菜单。除此之外,还有一些“下一步”和“上一步”按钮,供用户在链接菜单之间切换 我想改变这一点,使菜单将自动改变后,x的时间量 我想这样的事情可以做到:JavaScript运行完整的A href命令,javascript,html,Javascript,Html,我有一个网站,那里有一个充满链接的侧菜单。除此之外,还有一些“下一步”和“上一步”按钮,供用户在链接菜单之间切换 我想改变这一点,使菜单将自动改变后,x的时间量 我想这样的事情可以做到: <!DOCTYPE html> <html> <head> <script type="text/javascript"> function delayer(){ window.location = "http://www.google.com" } <
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function delayer(){
window.location = "http://www.google.com" }
</script>
</head>
<body onLoad="setTimeout('delayer()', 1000)">
</body>
</html>
函数延迟器(){
window.location=”http://www.google.com" }
基本上,我不想打开google,而是希望页面运行“下一步”按钮,该按钮由以下内容表示:
<div class="navBtns mar9 s3">
<a href="#" class="prev"><span></span></a>
<a href="#" class="next"><span></span></a>
</div>
你知道怎么做吗?谢谢
<a href="#" class="prev"><span></span></a>
此超链接本身不起任何作用。在站点的某个地方,有一个javascript函数绑定到此链接的单击事件。您需要在链接上触发单击事件,或者直接调用javascript
如果不了解页面上使用的其他javascript/框架,就不可能给出更精确的答案
--编辑--
根据您的评论,您可以按照以下思路做一些事情:
<script type="text/javascript">
setTimeout(function() {
$('#page_HOME .slider .next').click();
}, 1000);
</script>
setTimeout(函数(){
$('#page_HOME.slider.next')。单击();
}, 1000);
只要这些超链接包含在slider元素中,上述代码将在1000毫秒后触发侧菜单中的更改如果您想“单击”下一步按钮,那么您可以使用JS以编程方式进行更改
var nextbutton = document.getElementsByClassName('next');
nextbutton.click();
像这样按类获取元素只在后IE8浏览器上有效。您可以使用简单的旧JS,根据链接的类名找到所需链接的HREF
window.location=document.querySelector().getAttribute(“href”);
这会将浏览器重定向到href
属性设置为的任何位置
如果您想保持现有的功能,可以使用以下方法:
功能延迟(链路、时间){
setTimeout(函数(){
window.location=document.querySelector(“.”+linkClass).getAttribute(“href”);
},时间);
}
然后要使用它,只需说:
delay("next", 5000); // go to the href of the link with the class "next" after 5 seconds.
我如何回复你的帖子?我只看到评论?你是对的,它确实激活了更多的JavaScript。下面是它激活的内容:if($('#page_HOME.slider').length){$('#page_HOME.slider').cycle({fx:'scrollHorz',速度:600,超时:0,下一步:'.s3.next',上一步:'.s3.prev',放松:'easeOutCubic',cleartypeNoBg:true,版本:0,开始幻灯片:0,换行:true});如何将其添加到我的页面?例如,直接在delayer()函数中插入该代码,当重定向到google时将调用该代码。您只需在锚元素中添加一个href,它就可以执行任何有用的操作。