求高人将这段JS代码改成可放一个js文件里然后独立调用
<scripttype="text/javascript">functionshowLocale(objD){varstr;varyy=objD.getYear();if...
<script type="text/javascript">
function showLocale(objD)
{
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick();
</script>
<script language="livescript">
now = new Date(),hour = now.getHours()
if(hour < 5){document.write("天还没亮,请注意身体!")}
else if (hour < 8){document.write("早上好,祝你今天有好心情!")}
else if (hour < 12){document.write("上午好,祝你玩得开心!")}
else if (hour < 14){document.write("中午好,逛完记得午休哦!")}
else if (hour < 18){document.write("下午好,看看又更新了什么好东东!")}
else if (hour < 22){document.write("晚上好,感谢你对本站的支持!")}
else if (hour < 24){document.write("夜深了,早点休息吧,祝你梦想成真!")}
</script>
这个也加进去 展开
function showLocale(objD)
{
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick();
</script>
<script language="livescript">
now = new Date(),hour = now.getHours()
if(hour < 5){document.write("天还没亮,请注意身体!")}
else if (hour < 8){document.write("早上好,祝你今天有好心情!")}
else if (hour < 12){document.write("上午好,祝你玩得开心!")}
else if (hour < 14){document.write("中午好,逛完记得午休哦!")}
else if (hour < 18){document.write("下午好,看看又更新了什么好东东!")}
else if (hour < 22){document.write("晚上好,感谢你对本站的支持!")}
else if (hour < 24){document.write("夜深了,早点休息吧,祝你梦想成真!")}
</script>
这个也加进去 展开
展开全部
<script type="text/javascript" src=“js.js">
</script>
在dream里创建一个名为js的js文件 内容是
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick();
</script>
在dream里创建一个名为js的js文件 内容是
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick();
追问
无效、、感谢您的帮助
展开全部
<script type="text/javascript">
function showLocale(objD)
{
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick(a)
{
var today;
today = new Date();
document.getElementById(a).innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
</script>
====================================
上面的代码放到一个单独的JS里,用的时候直接调tick(a),其中a就是你用来显示用的那个地方,
如要在<td id="localtime"></td>里面显示时间。那么就是tick("localtime");这样就可以了,可以在body中调用<body onload="tick("localtime");">
function showLocale(objD)
{
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick(a)
{
var today;
today = new Date();
document.getElementById(a).innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
</script>
====================================
上面的代码放到一个单独的JS里,用的时候直接调tick(a),其中a就是你用来显示用的那个地方,
如要在<td id="localtime"></td>里面显示时间。那么就是tick("localtime");这样就可以了,可以在body中调用<body onload="tick("localtime");">
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function showLocale(objD)
{
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"+yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
//js 文件 t.js
//页面
<script src="t.js" type="text/javascript"></script>
<script type="text/javascript">
tick();
</script>
{
var str;
var yy = objD.getYear();
if(yy<1900) yy = yy+1900;
var MM = objD.getMonth()+1;
if(MM<10) MM = '0' + MM;
var dd = objD.getDate();
if(dd<10) dd = '0' + dd;
var hh = objD.getHours();
if(hh<10) hh = '0' + hh;
var mm = objD.getMinutes();
if(mm<10) mm = '0' + mm;
var ss = objD.getSeconds();
if(ss<10) ss = '0' + ss;
var ww = objD.getDay();
if (ww==0) ww="星期日";
if (ww==1) ww="星期一";
if (ww==2) ww="星期二";
if (ww==3) ww="星期三";
if (ww==4) ww="星期四";
if (ww==5) ww="星期五";
if (ww==6) ww="星期六";
str ="现在是:"+yy + "年" + MM + "月" + dd + "日" + " " + ww + " " + hh + ":" + mm + ":" + ss;
return(str);
}
function tick()
{
var today;
today = new Date();
document.getElementById("localtime").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
//js 文件 t.js
//页面
<script src="t.js" type="text/javascript"></script>
<script type="text/javascript">
tick();
</script>
追问
没效果、、感谢您的帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询