JavaScript实现跳转功能
利用JavaScript实现3秒跳转到百度界面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript实现跳转功能</title>
</head>
<body>
<p><span id="num">3</span>秒后跳转到<a href="http://www.baidu.com" id="a">百度</a>页面.或直接点击<a href="http://www.baidu.com">此处</a>跳转!</p>
<script type="text/javascript">
//先获取数字
var num = document.querySelector("#num");
//每个一秒减1
setInterval(jian, 1000);
function jian() {
var cur = num.innerText - 1;
if (cur == 0) {
//跳转
document.querySelector("#a").href
location.href = "http://www.baidu.com";
}
num.innerText = cur;
}
</script>
</body>
</html>