食道癌能不能 治愈:htm代码问题

来源:百度文库 编辑:高考问答 时间:2024/04/29 22:38:18
下面表示的日期和星期的代码
<script language="JavaScript">
<!--
today=new Date();
var date,thisyear,sun;
thisyear=today.getYear();
if(thisyear<=99) thisyear=thisyear+1900;
sun=today.getDay()
if(sun=0)sun="一";
else if(sun=1)sun="二";
else if(sun=2)sun="三";
else if(sun=3)sun="四";
else if(sun=4)sun="五";
else if(sun=5)sun="六";
else if(sun=6)sun="天";
date="今天是"+thisyear+"."+(today.getMonth()+1)+"."+today.getDate()+"星期"+sun
+"";
document.write(date.fontsize(2));
//-->
</script>
这样输出日期和星期间没有空格不好看,请问怎么打它们做成中间有空格的呀?
谢谢bkssoft和kengxie
但zuec你的经典好像有点问题
输出的是
**好! 年 月 日(中间是空的~)
就没了,是不是哪搞了呀?

date="今天是"+thisyear+"."+(today.getMonth()+1)+"."+today.getDate()+" 星期"+sun

在星期前加"&nbsp;",在html当中"&nbsp;"代表空格。不要拷贝我写的,自己用键盘打。就像这样:“&nbsp;星期”

<script language="JavaScript">
<!--
today=new Date();
var date,thisyear,sun;
thisyear=today.getYear();
if(thisyear<=99) thisyear=thisyear+1900;
sun=today.getDay()
if(sun=0)sun="一";
else if(sun=1)sun="二";
else if(sun=2)sun="三";
else if(sun=3)sun="四";
else if(sun=4)sun="五";
else if(sun=5)sun="六";
else if(sun=6)sun="天";
date="今天是"+thisyear+"."+(today.getMonth()+1)+"."+today.getDate()+"   星期"+sun
+"";
document.write(date.fontsize(2));
//-->
</script>

中间加 

一个更加经典的显示时间的js,我常用这个
<script language="javaScript">
<!--
now = new Date(),hour = now.getHours()
if(hour < 6){document.write("凌晨好!")}
else if (hour < 9){document.write("早上好!")}
else if (hour < 12){document.write("上午好!")}
else if (hour < 14){document.write("中午好!")}
else if (hour < 17){document.write("下午好!")}
else if (hour < 19){document.write("傍晚好!")}
else if (hour < 22){document.write("晚上好!")}
else {document.write("夜里好!")}// --></script>
</font>  
<SCRIPT language=JavaScript><!---
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = "<FONT COLOR=#ffffff>" + ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? "<BLINK><FONT COLOR=#ffffff>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=#ffffff>:</FONT></BLINK>") + minutes+"</FONT></FONT>";
timeValue += (hours >= 12) ? "<FONT COLOR=#ffffff><I><B>pm</B></I></FONT>" : "<FONT COLOR=#ffffff><B><I>am</I></B></FONT>";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=RED>星期日","<font color=black>星期一","<font color=black>星期二","<font color=black>星期三","<font color=black>星期四","<font color=black>星期五","<font color=GREEN>星期六"); document.write("<font color=#ffffff>",today.getYear(),"<font color=red>年","<font color=#ffffff>",today.getMonth()+1,"<font color=red>月","<font color=#ffffff>",today.getDate(),"<font color=red>日 </FONT>",d[today.getDay()+1]," ",timeValue); //--></SCRIPT>

date="今天是"+thisyear+" . "+(today.getMonth()+1)+" . "+today.getDate()+" 星期 " + sun
+"";
在双引号里加空格就行了