如何用js实现高考倒计时

JavaScript025

如何用js实现高考倒计时,第1张

这是2014年高考倒计时的代码,可以自己修改只需要更改BirthDay=new Date("7-6-2014")里面的数字就可以。测试可用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>无标题文档</title>

</head>

<body onload="show_date_time()">

<SCRIPT language=javascript>

function show_date_time(){

window.setTimeout("show_date_time()", 1000)

BirthDay=new Date("7-6-2014")

today=new Date()

timeold=(BirthDay.getTime()-today.getTime())

sectimeold=timeold/1000

secondsold=Math.floor(sectimeold)

msPerDay=24*60*60*1000

e_daysold=timeold/msPerDay

daysold=Math.floor(e_daysold)

e_hrsold=(e_daysold-daysold)*24

hrsold=Math.floor(e_hrsold)

e_minsold=(e_hrsold-hrsold)*60

minsold=Math.floor((e_hrsold-hrsold)*60)

seconds=Math.floor((e_minsold-minsold)*60)

span_dt_dt.innerHTML="<b><align=center><font color=00CC00>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"+"</b><br></font>"

}

</SCRIPT>

<b><align=center><font color=#ffffff>高考倒计时还有:</b></font>

<span id="span_dt_dt" style='align=center no:1px solid blackbackground-color:#FFFFFF' ></span>

</body>

</html>

var scount = 0

$(function () {

var start = setInterval(function () {

var dtstr = ""

var now = new Date()//初始化当前时间

var newdatr = new Date(now.getFullYear(), "05", "07", "00", "00", "00", "00")//初始化目标时间(这里的05实际上是六月)

var nowhms = now.getTime()//当前时间转换毫秒

var newhms = newdatr.getTime()//目标时间转换毫秒

var cha = newhms - nowhms//时间差(毫秒数)

if (cha >0) {

var day = parseInt(cha / (1000 * 60 * 60 * 24))//计算天数

var hh = parseInt((cha % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))//计算小时

var min = parseInt(((cha % (1000 * 60 * 60 * 24)) % (1000 * 60 * 60)) / (1000 * 60))//计算分钟

var ss = parseInt((((cha % (1000 * 60 * 60 * 24)) % (1000 * 60 * 60)) % (1000 * 60)) / 1000)//计算秒

if (ss == 0) {

scount += 1

}

//var ms = parseInt((((cha % (1000 * 60 * 60 * 24)) % (1000 * 60 * 60)) % (1000 * 60)) % 1000)

dtstr = day + "天" + hh + "小时" + min + "分钟" + ss + "秒"//+ ms + "毫秒"

}

$("#timestr").html(dtstr)

$("#flag").html("你已经续了" + scount + "分钟。")

}, 1000)

})

当你在浏览网页时,看到一个很漂亮的特效,你查看源代码时看到的是一队乱码,那多扫兴呀!根据本人的研究,总结出了三种解密方法,与大家分享!!

方法一:

有一种加密的办法是采用javascript的escape()函数,把某些符号、汉字等变成乱码,以达到迷惑人的目的。解密这种代码的办法是采用其反函数加以还原。下面是一个经过加密的例子:

<HTML>

<SCRIPT LANGUAGE="Javascript">

var Words ="%3Chtml%3E%3Cbody%20bgcolor%3D%22red%22%3E%3Cp%3E%u8FD9%u662F%u4F8B%u5B50%uFF01%uFF01%uFF1A%uFF09%3C/p%3E%3C/body%3E%3C/html%3E"

var NewWords

NewWords = unescape(Words)

document.write(NewWords)

</SCRIPT>

<BODY>

</BODY>

</HTML>

这种文件最好解密,一看就明白,关键是unescape()函数起了还原源代码的作用。要想看到加密前的代码是什么样子,可以用下面的办法:

<HTML><SCRIPT LANGUAGE="Javascript">

var Words ="%3Chtml%3E%3Cbody%20bgcolor%3D%22red%22%3E%3Cp%3E%u8FD9%u662F%u4F8B%u5B50%uFF01%uFF01%uFF1A%uFF09%3C/p%3E%3C/body%3E%3C/html%3E"

var NewWords

NewWords = unescape(Words)

NewWords=NewWords.toString()

function password(){

document.pw.txtpw.value=NewWords

}

</SCRIPT>

<BODY>

<form name=pw>

<input type=button onclick="password()" value="解密">

<br>

<textarea name="txtpw" cols="100" rows="100"></textarea>

</form>

</BODY>

</HTML>

方法二:

有一个软件叫HTMLEncrypt.exe,它就是把源代码进行加密的软件,这个软件的加密的原理是把字符转换。下面的例子是一个分帧的页面:

<html><head><script>

function Carbosoft( s ) { var sRet="" for(j=0 j< s.length j++ ){ var n= s.charCodeAt(j) if (n>=8364) {n = 128} sRet += String.fromCharCode( n - 3 ) } return( sRet ) }

var sJsCmds ="" +

"?kwpoA?khdgA?phwd#kwws0htxly@%Frqwhqw0W|sh%#frqwhqw@%wh{w2kwpo>#fkduvhw@lvr08<04%A?wlwohAZHOFRPH?2wlwohA?phwd#qdph@%JHQHUDWRU%#frqwhqw@%Plfurvriw#IurqwSdjh#613%A?phwd#qdph@%Plfurvriw#Wkhph%#frqwhqw@%qrqh/#ghidxow%A?phwd#qdph@%Plfurvriw#Erughu%#frqwhqw@%qrqh/#ghidxow%A?2khdgA?iudphvhw#erughu@%3%#iudpherughu@%3%#urzv@%-/93%A##?iudph#qdph@%pdlq%#vuf@%xs1kwp%#vfuroolqj@%dxwr%A##?iudph#qdph@%rqolqh%#vuf@%grzq1kwp%#vfuroolqj@%qr%#qruhvl}h#wdujhw@%beodqn%A##?qriudphvA##?erg|A##?sAWklv#sdjh#xvhv#iudphv/#exw#|rxu#eurzvhu#grhvq*w#vxssruw#wkhp1#?2sA##?2erg|A##?2qriudphvA?2iudphvhwA?2kwpoA?irqw#froru@%&33333%A?s#doljq@%fhqwhu%A?vpdooA?irqw#idfh@%Wdkrpd%AWklv#iloh#zdv#hqfu|swhg#xvlqj#dq#xquhjlvwhuhg#yhuvlrq#ri#?d#kuhi@%kwws=22fduer{1wkhgqv1qhw2kwpohqfu|sw1kwp%AKWPO#Hqfu|sw#y413?2dA1?2irqwA?2vpdooA?2sA" +

""

var s= Carbosoft( sJsCmds)

document.write (s)

</script>

</head><body></body></html>

从上面可以看出,浏览器解释这写代码前,进行了还原,从而可以得到破解的方法如下:

<script>

function Carbosoft( s ) { var sRet="" for(j=0 j< s.length j++ ){ var n= s.charCodeAt(j) if (n>=8364) {n = 128} sRet += String.fromCharCode( n - 3 ) } return( sRet ) }

var sJsCmds ="" +

"?kwpoA?khdgA?phwd#kwws0htxly@%Frqwhqw0W|sh%#frqwhqw@%wh{w2kwpo>#fkduvhw@lvr08<04%A?wlwohAZHOFRPH?2wlwohA?phwd#qdph@%JHQHUDWRU%#frqwhqw@%Plfurvriw#IurqwSdjh#613%A?phwd#qdph@%Plfurvriw#Wkhph%#frqwhqw@%qrqh/#ghidxow%A?phwd#qdph@%Plfurvriw#Erughu%#frqwhqw@%qrqh/#ghidxow%A?2khdgA?iudphvhw#erughu@%3%#iudpherughu@%3%#urzv@%-/93%A##?iudph#qdph@%pdlq%#vuf@%xs1kwp%#vfuroolqj@%dxwr%A##?iudph#qdph@%rqolqh%#vuf@%grzq1kwp%#vfuroolqj@%qr%#qruhvl}h#wdujhw@%beodqn%A##?qriudphvA##?erg|A##?sAWklv#sdjh#xvhv#iudphv/#exw#|rxu#eurzvhu#grhvq*w#vxssruw#wkhp1#?2sA##?2erg|A##?2qriudphvA?2iudphvhwA?2kwpoA?irqw#froru@%&33333%A?s#doljq@%fhqwhu%A?vpdooA?irqw#idfh@%Wdkrpd%AWklv#iloh#zdv#hqfu|swhg#xvlqj#dq#xquhjlvwhuhg#yhuvlrq#ri#?d#kuhi@%kwws=22fduer{1wkhgqv1qhw2kwpohqfu|sw1kwp%AKWPO#Hqfu|sw#y413?2dA1?2irqwA?2vpdooA?2sA" +

""

var s= Carbosoft( sJsCmds)

</script>

<form name=qq>

<textarea name=ww cols=100 rows=10></textarea>

<input onclick='ww.value=s' type=button value="解密">

</form>

方法三:

有一种加密方法是每行单独加密,还原起来比较复杂。看一个加密过的原文:

<HTML>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

function Decode() {

d("FrfmnD")d("FruyvDFgwhqjfWnyeseysuEXpydy%whqjf~J~XWghwEXfkjJpgXDFIgwhqjfD")d("FmufyWrffjKuieqdEX?klfulfK$ajuXWwklfulfEXfubfIrfmnGWwryhgufEsx}{~}XD")d("FfqfnuDejFIfqfnuD")d("FIruyvD")d("FxkvaD")d("FIxkvaD")d("FIrfmnD")d("W")return 0}

</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">

function d (enc) {document.write(codeIt(key,enc))}

var key = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"\ \|#$%&\'()*+,-.\/:<=>?@[\\]^_\t\`{}~\n"function codeIt (mC, eS) {var wTG, mcH = mC.length / 2, nS = "", dvfor (var x = 0 x < eS.length x++) { wTG = mC.indexOf(eS.charAt(x))if (wTG > mcH) {dv = wTG - mcH nS = nS + mC.charAt(48 - dv)}else {dv = mcH - wTGnS = nS + mC.charAt(48 + dv)}}return nS}

</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">

Decode()

</SCRIPT>

</BODY>

</HTML>

还原的时候,也必须每行单独解密,用下面的方法可以看到源代码:

<HTML>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

function Decode() {

d("FrfmnD")d("FruyvDFgwhqjfWnyeseysuEXpydy%whqjf~J~XWghwEXfkjJpgXDFIgwhqjfD")d("FmufyWrffjKuieqdEX?klfulfK$ajuXWwklfulfEXfubfIrfmnGWwryhgufEsx}{~}XD")d("FfqfnuDejFIfqfnuD")d("FIruyvD")d("FxkvaD")d("FIxkvaD")d("FIrfmnD")d("W")return 0}

</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">

function d (enc) {alert(codeIt(key,enc))}

var key = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"\ \|#$%&\'()*+,-.\/:<=>?@[\\]^_\t\`{}~\n"function codeIt (mC, eS) {var wTG, mcH = mC.length / 2, nS = "", dvfor (var x = 0 x < eS.length x++) { wTG = mC.indexOf(eS.charAt(x))if (wTG > mcH) {dv = wTG - mcH nS = nS + mC.charAt(48 - dv)}else {dv = mcH - wTGnS = nS + mC.charAt(48 + dv)}}return nS}

</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">

Decode()

</SCRIPT>

</BODY>

</HTML>

哈哈!!:=)是不是很精彩!!