首页 > 语言 > JavaScript > 正文

常用的几段javascript代码分享

2024-05-06 16:03:13
字体:
来源:转载
供稿:网友
这篇文章主要介绍了常用的几段javascript代码,需要的朋友可以参考下

1.3秒后自动返回

复制代码 代码如下:


<span>3</span>秒后自动返回

<script language="javascript" type="text/javascript">
<!--
var second = document.getElementById('totalSecond').textContent;
if (navigator.appName.indexOf("Explorer") > -1) //判断是IE浏览器还是Firefox浏览器,采用相应措施取得秒数
{
second = document.getElementById('totalSecond').innerText;
} else
{
second = document.getElementById('totalSecond').textContent;
}
setInterval("redirect()", 1000); //每1秒钟调用redirect()方法一次
function redirect()
{
if (second < 0)
{
location.href = 'http://www.baidu.com';
} else
{
if (navigator.appName.indexOf("Explorer") > -1)
{
document.getElementById('totalSecond').innerText = second--;
} else
{
document.getElementById('totalSecond').textContent = second--;
}
}
}
-->
</script>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选