下面举例说明,在2秒后,自动跳到百度首页的几种方法。

1.html的实现

< head>
< !-- 以下方式只是刷新不跳转到其他页面 -->
< me ta http-equiv="refresh" content="2">
< !-- 以下方式定时转到其他页面 -->
< me ta http-equiv="refresh" content="2;url=http://www.baidu.com">
< /head>

这种方法比较简单!

2.javascript的实现

< script language="javascript" type="text/javascript">
//以下方式直接跳转
window.location.href='http://www.baidu.com';
//以下方式定时跳转
setTimeout("javascript:location.href='http://www.baidu.com'", 2000);
< /script>

这种方法比较灵活,可以结合更多的其他功能使用;但是会受到不同浏览器的影响。

html代码因受格式限制,在代码间加入空格。注意!!

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐