⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1date.htm

📁 JavaScript实例
💻 HTM
字号:
<html>
<head>
<title>洪恩在线 - Javascript实例</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../homepage.css">
</head>

<body bgcolor="#FFFFFF">
<script language="Javascript" src="/pub/js/head.js"></script>
<table width="760" height="20" border=0 cellspacing="0" cellpadding="0" align="center">
  <tr bgcolor="CFDFFF"> 
    <td height=20 class="p1" align="left"><img src="/pc/img/blank.gif" width="12" height="8"><font color="#000000"><font color="#FF9966">当前位置</font>:<a href="/default.htm" class="under">洪恩在线</a> 
      -&gt; <a href="/pc/index.htm" class="under">电脑乐园</a> -&gt; JavaScript实例</font></td>
  </tr>
</table>
<table width="760" border=0 cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td width="207" valign="top"><img src="img/bule.gif" width="207" height="13"></td>
    <td bgcolor="A8A8AB" width="1"><img src="img/blank.gif" width="1" height="1"></td>
    <td align="right" height="22" width=530><img src="img/js.gif" width="186" height="20"></td>
    <td width="22"><img src="img/blank.gif" width="1" height="1"></td>
  </tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td width="124"><img src="img/blank.gif" width="1" height="1"></td>
    <td background="img/line.gif" height="27" width=636><img src="img/blank.gif" width="1" height="1"></td>
  </tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td class=p3 align="center" width=711><b>     日期星期的显示</b></td>
    <td width="1" bgcolor="A8A8AB"><img src="img/blank.gif" width="1" height="1"></td>
    <td class="p2" width="48"><img src="img/blank.gif" width="1" height="1"></td>
  </tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td align="center" valign="top">&nbsp;</td>
    <td>&nbsp;</td>
    <td bgcolor="5F74BF" width="28" align="center"><img src="img/bule1.gif" width="28" height="49"></td>
    <td width="37" align="center">&nbsp;</td>
  </tr>
  <tr> 
    <td align="center" valign="top"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr align="center"> 
          <td> 
            <table width="110" border="0" cellspacing="0" cellpadding="0">
              <tr bgcolor="5F74BF" align="center"> 
                <td class="p1" align="right"><b><font color="#FFFFFF">效 果 演 示</font></b><font color="#FFFFFF">:</font></td>
                <td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
    <td> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align=center width="34" height="172" ><font color=red> </font></td>
          <td align=center width="255" background="img/date.jpg" height="172" ><font color=blue> 
            <script language="JavaScript">
<!--
todayDate = new Date();
date = todayDate.getDate();
month= todayDate.getMonth() +1;
year= todayDate.getYear();
document.write("今天是")
document.write("<br>")
if(navigator.appName == "Netscape")
{
	document.write(1900+year);
	document.write("年");
	document.write(month);
	document.write("月");
	document.write(date);
	document.write("日");
	document.write("<br>")
}
if(navigator.appVersion.indexOf("MSIE") != -1)
{
document.write(year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日");
document.write("<br>")
}
if (todayDate.getDay() == 5) document.write("星期五")
if (todayDate.getDay() == 6) document.write("星期六")
if (todayDate.getDay() == 0) document.write("星期日")
if (todayDate.getDay() == 1) document.write("星期一")
if (todayDate.getDay() == 2) document.write("星期二")
if (todayDate.getDay() == 3) document.write("星期三")
if (todayDate.getDay() == 4) document.write("星期四")

//--> 
</script>
            </font></td>
          <td align=center width="167" height="172" >&nbsp;</td>
          <td width="1">&nbsp;</td>
        </tr>
      </table>
      <br>
      
    </td>
    <td bgcolor="5F74BF" width="28" align="center">&nbsp;</td>
    <td width="37" align="center">&nbsp;</td>
  </tr>
  <tr> 
    <td align="center" valign="top"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td height="30">&nbsp;</td>
        </tr>
        <tr align="center"> 
          <td> 
            <table width="110" border="0" cellspacing="0" cellpadding="0">
              <tr bgcolor="5F74BF" align="center"> 
                <td class="p1" align="right"><b><font color="#FFFFFF">源代码如下</font></b><font color="#FFFFFF">:</font></td>
                <td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
    <td width="457" class="p2" valign="top"><b><br>
      <br>
      </b><span class="p1"><font color="#6633FF"><br>
      这段程序放在&lt;body&gt;与&lt;/body&gt;之间</font></span><br>
      <form>
        <textarea name="textarea" onFocus="this.select()" onMouseOver="this.focus()" cols="50" rows="12" wrap="VIRTUAL" style="BACKGROUND-COLOR: #D5E9FD;" >&lt;!--
todayDate = new Date();
date = todayDate.getDate();
month= todayDate.getMonth() +1;
year= todayDate.getYear();
document.write(&quot;今天是&quot;)
document.write(&quot;&lt;br&gt;&quot;)
if(navigator.appName == &quot;Netscape&quot;)
{
	document.write(1900+year);
	document.write(&quot;年&quot;);
	document.write(month);
	document.write(&quot;月&quot;);
	document.write(date);
	document.write(&quot;日&quot;);
	document.write(&quot;&lt;br&gt;&quot;)
}
if(navigator.appVersion.indexOf(&quot;MSIE&quot;) != -1)
{
document.write(year);
document.write(&quot;年&quot;);
document.write(month);
document.write(&quot;月&quot;);
document.write(date);
document.write(&quot;日&quot;);
document.write(&quot;&lt;br&gt;&quot;)
}
if (todayDate.getDay() == 5) document.write(&quot;星期五&quot;)
if (todayDate.getDay() == 6) document.write(&quot;星期六&quot;)
if (todayDate.getDay() == 0) document.write(&quot;星期日&quot;)
if (todayDate.getDay() == 1) document.write(&quot;星期一&quot;)
if (todayDate.getDay() == 2) document.write(&quot;星期二&quot;)
if (todayDate.getDay() == 3) document.write(&quot;星期三&quot;)
if (todayDate.getDay() == 4) document.write(&quot;星期四&quot;)

//--&gt; </textarea>
      </form>
      <br>
      </td>
    <td bgcolor="5F74BF" width="28" align="center">&nbsp;</td>
    <td width="37" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td align="center" valign="bottom"> 
      <table width="238" border="0" cellspacing="0" cellpadding="0">
        <tr align="center"> 
          <td> 
            <table width="110" border="0" cellspacing="0" cellpadding="0" class=p2>
              <tr bgcolor="5F74BF" align="center"> 
                <td class="p1" align="right"><b><font color="#FFFFFF">源程序讲解:</font></b></td>
                <td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
    <td width="457" class="p2" valign="top">&nbsp;</td>
    <td bgcolor="5F74BF" width="28" align="center"><img src="img/bule1.gif" width="28" height="49"></td>
    <td width="37" align="center">&nbsp;</td>
  </tr>
</table>

<table width="760" border="0" cellspacing="0" cellpadding="0" align="center" class=p2>
  <tr> 
    <td class="p2" align="right" width="693"> <br>
      <table width="650" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td> 
            <table width="100%" border="1" cellspacing="1" cellpadding="1" bordercolorlight="#666666" bordercolordark="#666666" class=p2>
              <tr> 
                <td width="270">todayDate = new Date();<br>
                </td>
                <td width="490">当定义一个新的对象时,通常使用“new”操作符。在这里,就是创建了日期对象。</td>
              </tr>
              <tr> 
                <td width="270" bgcolor="CFDFFF">date = todayDate.getDate();<br>
                  <br>
                </td>
                <td width="490" bgcolor="CFDFFF">getDate()是Date对象的一种方法,其功能是获得当前的日期。</td>
              </tr>
              <tr> 
                <td width="270">month= todayDate.getMonth() + 1 ;<br>
                  ; </td>
                <td width="490">getMonth()是Date对象的一种方法,其功能是获得当前的日期,由于月份是从0开始的,所以这里要“+1”。</td>
              </tr>
              <tr> 
                <td width="270" bgcolor="CFDFFF">year= todayDate.getYear()</td>
                <td width="490" bgcolor="CFDFFF">getYear()是Date对象的一种方法,其功能是获得当前的年份。</td>
              </tr>
              <tr> 
                <td width="270">document.write("今天是") document.write("&lt;br&gt;")</td>
                <td width="490">输出“今天是”</td>
              </tr>
              <tr> 
                <td width="270" bgcolor="CFDFFF">if(navigator.appName == "Netscape") 
                  { document.write(1900+year); document.write("年"); document.write(month); 
                  document.write("月"); document.write(date); document.write("日");<br>
                  document.write("&lt;br&gt; ") } </td>
                <td width="490" bgcolor="CFDFFF">如果浏览器是Netscape,输出今天是“year”+“年”+“month”+“月”+“date”+“日”,其中年要加1900。</td>
              </tr>
              <tr> 
                <td width="270">if(navigator.appVersion.indexOf("MSIE") != -1) 
                  { document.write(year); document.write("年"); document.write(month); 
                  document.write("月"); document.write(date); document.write("日");<br>
                  document.write("&lt;br&gt; ") }</td>
                <td width="490">如果浏览器是IE,直接输出今天是“year”+“年”+“month”+“月”+“date”+“日”。</td>
              </tr>
              <tr> 
                <td width="270" bgcolor="CFDFFF">document.write("

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -