JS定时调用不同JS
<body><divid="di"></div></body><scripttype='text/javascript'>window.onLoad=newfunctio...
<body>
<div id="di"></div>
</body>
<script type='text/javascript'>
window.onLoad = new function(){
setInterval("checkTime()",1000);
}
function checkTime(){
var myDate = new Date();
var hour = myDate.getHours();
if(hour >= 18 || hour <= 7){
document.getElementById("di").innerHTML = "<script type='text/javascript' language='javascript' src='1.asp'></script>";
}
else{
document.getElementById("di").innerHTML = "<script type='text/javascript' language='javascript' src='2.asp'></script>";
}
}
</script>
</body>
如何在不同时段调用不同的JS!谢谢! 展开
<div id="di"></div>
</body>
<script type='text/javascript'>
window.onLoad = new function(){
setInterval("checkTime()",1000);
}
function checkTime(){
var myDate = new Date();
var hour = myDate.getHours();
if(hour >= 18 || hour <= 7){
document.getElementById("di").innerHTML = "<script type='text/javascript' language='javascript' src='1.asp'></script>";
}
else{
document.getElementById("di").innerHTML = "<script type='text/javascript' language='javascript' src='2.asp'></script>";
}
}
</script>
</body>
如何在不同时段调用不同的JS!谢谢! 展开
展开全部
window.onLoad = new function(){
setInterval("checkTime()",1000);
}
function checkTime(){
var myDate = new Date();
var hour = myDate.getHours();
if(hour >= 18 || hour <= 7){
insertJS('1.asp')
}
else{
insertJS('2.asp')
}
}
function insertJS(url, callback){
var script = document.createElement("SCRIPT"), done = false;
script.type = "text/javascript";
script.src = url;
script.charset = "GB2312";
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
callback && callback();
}
};
document.getElementsByTagName("HEAD")[0].appendChild(script);
}
这样就行了
setInterval("checkTime()",1000);
}
function checkTime(){
var myDate = new Date();
var hour = myDate.getHours();
if(hour >= 18 || hour <= 7){
insertJS('1.asp')
}
else{
insertJS('2.asp')
}
}
function insertJS(url, callback){
var script = document.createElement("SCRIPT"), done = false;
script.type = "text/javascript";
script.src = url;
script.charset = "GB2312";
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
callback && callback();
}
};
document.getElementsByTagName("HEAD")[0].appendChild(script);
}
这样就行了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询