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

📄 cook2.htm

📁 javascript各种效果的实例及源代码
💻 HTM
字号:
<html>

<head>

<title>集成Cookies</title>

<style type="text/css">

<!--

body {  font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 0px; margin-right: 0px}

A { COLOR: black; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: none }

 A:hover { COLOR: red; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: underline }

a:active     { font: 9pt "宋体"; cursor: hand; color: #FF0033 }



-->

</style>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>



<body bgcolor="#fef4d9" onLoad="startclock()"> 

<br>

<br>

<center><font color=red face="隶书" size=6>集成Cookies</font></center>

<br>

<center>

<table border=5 bordercolor=blue borderlight=green>

<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面为效果显示区!</strong></font></td></tr><tr><td align=center height=200 width=400>

<SCRIPT language="JavaScript"><!--

function getCookieVal (offset) 

   {

   var endstr = document.cookie.indexOf (";", offset);

   if (endstr == -1)

      endstr = document.cookie.length;

   return unescape(document.cookie.substring(offset, endstr));

   }

function GetCookie (name) 

   {

   var arg = name + "=";

   var alen = arg.length;

   var clen = document.cookie.length;

   var i = 0;

   while (i < clen) 

      {

      var j = i + alen;

      if (document.cookie.substring(i, j) == arg)

         return getCookieVal (j);

      i = document.cookie.indexOf(" ", i) + 1;

      if (i == 0) 

         break; 

      }

   return null;

   }

function SetCookie (name, value) 

   {

   var argv = SetCookie.arguments;

   var argc = SetCookie.arguments.length;

   var expires = (2 < argc) ? argv[2] : null;

   var path = (3 < argc) ? argv[3] : null;

   var domain = (4 < argc) ? argv[4] : null;

   var secure = (5 < argc) ? argv[5] : false;

   document.cookie = name + "=" + escape (value) +

     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

     ((path == null) ? "" : ("; path=" + path)) +

     ((domain == null) ? "" : ("; domain=" + domain)) +

	((secure == true) ? "; secure" : "");

   }

function ResetCounts(name)

   {

   visits = 0;

   SetCookie("visits", visits, expdate , "java2000.wol.com.html", null, false);

   location.reload();

   }

//-->

</SCRIPT><br><SCRIPT language="JavaScript"><!--

var expdate = new Date();



var visits;



// Set expiration date to a year from now.



expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 



if(!(visits = GetCookie("visits"))) 



   visits = 0;



visits++;



SetCookie("visits", visits, expdate, "java2000.wol.com.html", null, false);



   if(visits == 1) 



      document.write('<P><CENTER>Welcome Cadet '+username+'</CENTER>');



   if(visits == 2) 



      document.write('<P><CENTER>Welcome Ensign '+username+'</CENTER>');



   if(visits == 3) 



      document.write('<P><CENTER>Welcome Lieutenant '+username+'</CENTER>');



   if(visits == 4) 



      document.write('<P><CENTER>Welcome Lieutenant-Commander '+username+'</CENTER>');



   if(visits == 5) 



      document.write('<P><CENTER>Welcome Commander '+username+'</CENTER>');



   if(visits == 6) 



      document.write('<P><CENTER>Welcome Vice-Admiral '+username+'</CENTER>');



   if(visits == 7) 



      document.write('<P><CENTER>Welcome Admiral '+username+'</CENTER>');



   if(visits== 8) 



      document.write('<P><CENTER>Welcome Demi-God '+username+'</CENTER>');



   if(visits== 9) 



      document.write('<P><CENTER>Welcome Demi-God '+username+'</CENTER>');



   if(visits>=10) 



      document.write('<P><CENTER>Welcome Master '+username+'</CENTER>');







//-->



</SCRIPT><br>



<FONT FACE="宋体" size="3" color=red>



<b>我猜你使用的系统为:

<SCRIPT language="javascript">document.write(document.referrer)</SCRIPT><br>

Using <SCRIPT language="javascript">document.write(navigator.userAgent)</SCRIPT>

</b></font><br><SCRIPT language="JavaScript"><!--

var expdate = new Date();



var visits;



expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 



if(!(visits = GetCookie("visits"))) 



   visits = 0;



visits++;



SetCookie("visits", visits, expdate, "www.njcatv.net.html", null, false);



document.write(""+"你已经光临本页"+visits+" 次了.谢谢!");





//-->



</SCRIPT><br>

你的登录时间为:<br><SCRIPT language="JavaScript"><!--

Stamp = new Date();

	var Hours;

	var Mins;

	var Time;

	Hours = Stamp.getHours();

	if (Hours >= 12) {

	        Time = " P.M.";

	}

        else {

                Time = " A.M.";

        }

	

	if (Hours > 12) {

        	Hours -= 12;

        }

	if (Hours == 0) {

        	Hours = 12;

        }

	Mins = Stamp.getMinutes();

	if (Mins < 10) {

        	Mins = "0" + Mins;

        }

	

	document.write('<font size="2" face="Arial"><B>' + Hours + ":" + Mins + Time + '</B></font>');

//-->



</SCRIPT><br>

现在时间是:<br><SCRIPT language="JavaScript"><!--

function goback(){

alert("Good Bye!");

history.go(-1);

}

function gettheDate() {

Todays = new Date();

TheDate = "" + (Todays.getMonth()+ 1) +" / "+ Todays.getDate() + " / " + 

Todays.getYear() 

document.clock.date.value = TheDate;

}

// Navigation - Stop

// Netscapes Clock - Start

// this code was taken from Netscapes JavaScript documentation at

// www.netscape.com on Jan.25.96



var timerID = null;

var timerRunning = false;

function stopclock (){

        if(timerRunning)

                clearTimeout(timerID);

        timerRunning = false;

}



function startclock () {

        // Make sure the clock is stopped

        stopclock();

        gettheDate()

        showtime();

}



function showtime () {

        var now = new Date();

        var hours = now.getHours();

        var minutes = now.getMinutes();

        var seconds = now.getSeconds()

        var timeValue = "" + ((hours >12) ? hours -12 :hours)

        timeValue += ((minutes < 10) ? ":0" : ":") + minutes

        timeValue += ((seconds < 10) ? ":0" : ":") + seconds

        timeValue += (hours >= 12) ? " P.M." : " A.M."

        document.clock.face.value = timeValue;

        // you could replace the above with this

        // and have a clock on the status bar:

        // window.status = timeValue;

        timerID = setTimeout("showtime()",1000);

        timerRunning = true;

}

//-->



</SCRIPT><br><form name="clock" onSubmit="0">

<div align=center>

<b><font size="-1"></font></b>

<input type="text" name="date" size=12 value="">

<input type="text" name="face" size=12 value="">

</div>

</form></td></tr>

</table></center>



<br>

<br>

<center>

<textarea name=source rows=12 cols=55 class=yk9>

脚本说明:

第一步:把如下代码加入<body>区域中

<SCRIPT language="JavaScript"><!--

function getCookieVal (offset) 

   {

   var endstr = document.cookie.indexOf (";", offset);

   if (endstr == -1)

      endstr = document.cookie.length;

   return unescape(document.cookie.substring(offset, endstr));

   }

function GetCookie (name) 

   {

   var arg = name + "=";

   var alen = arg.length;

   var clen = document.cookie.length;

   var i = 0;

   while (i < clen) 

      {

      var j = i + alen;

      if (document.cookie.substring(i, j) == arg)

         return getCookieVal (j);

      i = document.cookie.indexOf(" ", i) + 1;

      if (i == 0) 

         break; 

      }

   return null;

   }

function SetCookie (name, value) 

   {

   var argv = SetCookie.arguments;

   var argc = SetCookie.arguments.length;

   var expires = (2 < argc) ? argv[2] : null;

   var path = (3 < argc) ? argv[3] : null;

   var domain = (4 < argc) ? argv[4] : null;

   var secure = (5 < argc) ? argv[5] : false;

   document.cookie = name + "=" + escape (value) +

     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

     ((path == null) ? "" : ("; path=" + path)) +

     ((domain == null) ? "" : ("; domain=" + domain)) +

	((secure == true) ? "; secure" : "");

   }

function ResetCounts(name)

   {

   visits = 0;

   SetCookie("visits", visits, expdate , "java2000.wol.com.html", null, false);

   location.reload();

   }

//-->

</SCRIPT><br><SCRIPT language="JavaScript"><!--

var expdate = new Date();



var visits;



// Set expiration date to a year from now.



expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 



if(!(visits = GetCookie("visits"))) 



   visits = 0;



visits++;



SetCookie("visits", visits, expdate, "java2000.wol.com.html", null, false);



   if(visits == 1) 



      document.write('<P><CENTER>Welcome Cadet '+username+'</CENTER>');



   if(visits == 2) 



      document.write('<P><CENTER>Welcome Ensign '+username+'</CENTER>');



   if(visits == 3) 



      document.write('<P><CENTER>Welcome Lieutenant '+username+'</CENTER>');



   if(visits == 4) 



      document.write('<P><CENTER>Welcome Lieutenant-Commander '+username+'</CENTER>');



   if(visits == 5) 



      document.write('<P><CENTER>Welcome Commander '+username+'</CENTER>');



   if(visits == 6) 



      document.write('<P><CENTER>Welcome Vice-Admiral '+username+'</CENTER>');



   if(visits == 7) 



      document.write('<P><CENTER>Welcome Admiral '+username+'</CENTER>');



   if(visits== 8) 



      document.write('<P><CENTER>Welcome Demi-God '+username+'</CENTER>');



   if(visits== 9) 



      document.write('<P><CENTER>Welcome Demi-God '+username+'</CENTER>');



   if(visits>=10) 



      document.write('<P><CENTER>Welcome Master '+username+'</CENTER>');







//-->



</SCRIPT><br>



<FONT FACE=ARIAL size="2">



<b>Your access was granted from

<SCRIPT language="javascript">document.write(document.referrer)</SCRIPT><br>

Using <SCRIPT language="javascript">document.write(navigator.userAgent)</SCRIPT>

</b></font><br><SCRIPT language="JavaScript"><!--

var expdate = new Date();



var visits;



expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 



if(!(visits = GetCookie("visits"))) 



   visits = 0;



visits++;



SetCookie("visits", visits, expdate, "www.njcatv.net.html", null, false);



document.write(""+"你已经光临本页"+visits+" 次了.谢谢!");





//-->



</SCRIPT><br>

You arrived at <br><SCRIPT language="JavaScript"><!--

Stamp = new Date();

	var Hours;

	var Mins;

	var Time;

	Hours = Stamp.getHours();

	if (Hours >= 12) {

	        Time = " P.M.";

	}

        else {

                Time = " A.M.";

        }

	

	if (Hours > 12) {

        	Hours -= 12;

        }

	if (Hours == 0) {

        	Hours = 12;

        }

	Mins = Stamp.getMinutes();

	if (Mins < 10) {

        	Mins = "0" + Mins;

        }

	

	document.write('<font size="2" face="Arial"><B>' + Hours + ":" + Mins + Time + '</B></font>');

//-->



</SCRIPT><br>

The current time is:<br><SCRIPT language="JavaScript"><!--

function goback(){

alert("Good Bye!");

history.go(-1);

}

function gettheDate() {

Todays = new Date();

TheDate = "" + (Todays.getMonth()+ 1) +" / "+ Todays.getDate() + " / " + 

Todays.getYear() 

document.clock.date.value = TheDate;

}

// Navigation - Stop

// Netscapes Clock - Start

// this code was taken from Netscapes JavaScript documentation at

// www.netscape.com on Jan.25.96



var timerID = null;

var timerRunning = false;

function stopclock (){

        if(timerRunning)

                clearTimeout(timerID);

        timerRunning = false;

}



function startclock () {

        // Make sure the clock is stopped

        stopclock();

        gettheDate()

        showtime();

}



function showtime () {

        var now = new Date();

        var hours = now.getHours();

        var minutes = now.getMinutes();

        var seconds = now.getSeconds()

        var timeValue = "" + ((hours >12) ? hours -12 :hours)

        timeValue += ((minutes < 10) ? ":0" : ":") + minutes

        timeValue += ((seconds < 10) ? ":0" : ":") + seconds

        timeValue += (hours >= 12) ? " P.M." : " A.M."

        document.clock.face.value = timeValue;

        // you could replace the above with this

        // and have a clock on the status bar:

        // window.status = timeValue;

        timerID = setTimeout("showtime()",1000);

        timerRunning = true;

}

//-->



</SCRIPT><br><form name="clock" onSubmit="0">

<div align=center>

<b><font size="-1"></font></b>

<input type="text" name="date" size=12 value="">

<input type="text" name="face" size=12 value="">

</div>

</form>



第二步:把<body>改为

<body bgcolor="#fef4d9" onLoad="startclock()"> 

</textarea>

<SCRIPT LANGUAGE="JavaScript">



<!-- hide



function goHist(a) 



{



   history.go(a);



}



//-->



</script>



<FORM METHOD="post">

<INPUT TYPE="button" VALUE="返回" onClick="goHist(-1)" style="background-color: #8000FF; color: rgb(255,255,255)">

</form>

</center>

<br>

<br>

</body>

</html>

⌨️ 快捷键说明

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