当用户访问首页index.html时,设定跳转时间,跳转到随机文章页面如/news/???.html,如何实现?
"???"为某个指定的区间,如1-100
:
window.location.href=“window.location.href"+"?id="
:
var id = Math.round()
:
window.location.href=“window.location.href"+"?id=" +id
:
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", i); // 匹配目标参数
var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
if (result != null) {
return decodeURIComponent(result[2]);
} else {
return null;
}
}
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", i); // 匹配目标参数
var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
if (result != null) {
return decodeURIComponent(result[2]);
} else {
return null;
}
}
<script>
function goPage(){
//alert("13123213213");
var id = Math.round(Math.random()*14+1); //其中14+1代表随时为1到15之间的数字,如是14则代表0到14之间的随机数字
console.log(id);
location.href="/article/"+id+".php";
}
var t=setInterval("goPage()",2000);
</script>