javascriptオブジェクトの結び目
39646 ワード
//lt;[CDATA[&腣13;
//タイマー&钾13;
function countTime(){&噫13;
var target Time=new Date(2010,6,24,12,0,0,0,0);
var nowTime=new Date()&莹13;
//目標時間と菗13;
var distanTime=target Time.getTime()-nowTime.getTime();&唵13;
days=Math.flor(distanTime/1000/60/60/24);
houss=Math.flor(distanTime/1000/60/60-(24*days);
minutes=Math.flor(distanTime/1000/60-(24*60*days)-(60*houss);
seconds=distanTime/1000-(24*60*60*days)-(60*houss)-(60*minutes);
secondsRound=Math.round(seconds);
&噫13;
Dcument.getElemenntById(「days」).innerHTML=「<font=redgt;」+days+「</font>」
Dcument.getElemenntById(「time」).inners=hors+「:」+minutes+「:」+seconds Round;&唫啱13;
}&{13;
set Interval(「countTime()」、250);
//gt;
ある日まで 空
今回は主にいくつかの主要な対象をテストして、string、date、配列を含みます.dateオブジェクトを使ってカウントダウンのような機能を作りました.
//タイマー&钾13;
function countTime(){&噫13;
var target Time=new Date(2010,6,24,12,0,0,0,0);
var nowTime=new Date()&莹13;
//目標時間と菗13;
var distanTime=target Time.getTime()-nowTime.getTime();&唵13;
days=Math.flor(distanTime/1000/60/60/24);
houss=Math.flor(distanTime/1000/60/60-(24*days);
minutes=Math.flor(distanTime/1000/60-(24*60*days)-(60*houss);
seconds=distanTime/1000-(24*60*60*days)-(60*houss)-(60*minutes);
secondsRound=Math.round(seconds);
&噫13;
Dcument.getElemenntById(「days」).innerHTML=「<font=redgt;」+days+「</font>」
Dcument.getElemenntById(「time」).inners=hors+「:」+minutes+「:」+seconds Round;&唫啱13;
}&{13;
set Interval(「countTime()」、250);
//gt;
ある日まで 空
今回は主にいくつかの主要な対象をテストして、string、date、配列を含みます.dateオブジェクトを使ってカウントダウンのような機能を作りました.
<!
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/html; charset=utf-8
"
/
>
<
title
>
javascript
<
/
title>
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
var
regExp
=
/
\s\*
/
g;
/*
---------------string ------------------
*/
var
str
=
"
this *is *test *string
"
;
var
sTxt
=
str.charAt(
3
);
var
aTxt
=
str.charCodeAt(
3
);
var
btxt
=
str.indexOf(
"
s
"
);
var
cTxt
=
str.slice(
0
,
4
);
var
dTxt
=
str.split(
"
"
);
var
subTxt
=
str.substr(
0
,
4
);
var
regTxt
=
str.match(regExp);
var
regSearchTxt
=
str.search(regExp);
document.writeln(
"
:
"
+
str
+
"
<br />
"
);
document.writeln(
"
charAt(3), :
"
+
sTxt
+
"
<br />
"
);
document.writeln(
"
charCodeAt(3), unicode :
"
+
aTxt
+
"
<br />
"
);
document.writeln(
"
indexOf,
"
+
btxt
+
"
<br />
"
);
document.writeln(
"
slice(0,4), 0,4 :
"
+
cTxt
+
"
<br />
"
);
document.writeln(
"
split(' '), :
"
+
dTxt
+
"
<br />
"
);
document.writeln(
"
substr(0,4), :
"
+
subTxt
+
"
<br />
"
);
document.writeln(
"
match, :
"
+
regTxt
+
"
<br />
"
);
document.writeln(
"
search, :
"
+
regSearchTxt
+
"
<br />
"
);
/*
----------------- ---------------
*/
//
test
var
result_tst
=
regExp.test(str);
document.writeln(
"
regExp.test(str), :
"
+
result_tst
+
"
<br />
"
);
//
exec
var
result_exec
=
regExp.exec(str);
document.writeln(
"
:
"
+
result_exec
+
"
<br />
"
);
var
result
=
str.replace(regExp,
"
_
"
);
document.writeln(
"
:
"
+
result
+
"
<br/>
"
);
//
var
reg2
=
/
:\s*\w*\s*[0-9]+\s[0-9]{4}
/
;
var
reg1
=
/
:\D*\s*\d+\s\d+
/
;
var
reg3
=
/
w*@w+.w
/
;
var
str2
=
"
this is a date: march 12 2010
"
;
var
eTxt
=
str2.match(reg2);
document.writeln(eTxt
+
"
<br/ >
"
);
//
*----------------Date --------------------*/
var
now
=
new
Date();
var
hours
=
now.getHours()
+
7
*
24
;
now.setHours(hours);
document.write(
"
:
"
+
now
+
"
<br/>
"
);
document.write(
"
"
+
now.getFullYear()
+
"
"
+
(now.getMonth()
+
1
)
+
"
"
+
now.getDate()
+
"
"
+
now.getHours()
+
"
"
+
now.getMinutes()
+
"
"
+
now.getSeconds()
+
"
"
+
"
<br/>
"
);
//
function
countTi<!--mce:1--> <!--mce:2--> <!--mce:3--> <!--mce:4--> <!--mce:5--> me(){
var
targetTime
=
new
Date(
2010
,
6
,
24
,
12
,
0
,
0
,
0
);
var
nowTime
=
new
Date();
//
var
distanTime
=
targetTime.getTime()
-
nowTime.getTime();
days
=
Math.floor( distanTime
/
1000
/
60
/
60
/
24
);
hours
=
Math.floor(distanTime
/
1000
/
60
/
60
-
(
24
*
days));
minutes
=
Math.floor( distanTime
/
1000
/
60
-
(
24
*
60
*
days)
-
(
60
*
hours));
seconds
=
distanTime
/
1000-(24*60*60*days)-(60*60*hours)-(60*minutes);
secondsRound
=
Math.round(seconds);
document.getElementById(
"
days
"
).innerHTML
=
"
<font color=red>
"
+
days
+
"
</font>
"
;
document.getElementById(
"
time
"
).innerHTML
=
hours
+
"
:
"
+
minutes
+
"
:
"
+
secondsRound;
}
setInterval(
"
countTime()
"
,
250
);
//
var
firstArr
=
new
Array(
"
one
"
,
"
two
"
,
"
three
"
);
var
secondArr
=
[
"
one
"
,
"
two
"
,
"
three
"
];
var
remove
=
firstArr.slice(
2
,
3
);
var
splicArr
=
secondArr.splice(
1
,
1
);
document.writeln(remove
+
"
<br/>
"
);
document.writeln(splicArr
+
"
<br/>
"
);
//
var
fifoArr
=
new
Array();
fifoArr.push(
"
apple
"
);
fifoArr.push(
"
banana
"
);
var
length
=
fifoArr.push(
"
cherry
"
);
document.writeln(
"
:
"
+
length
+
"
:
"
+
fifoArr
+
"
<br />
"
);
fifoArr.shift();
document.writeln(
"
shift :
"
+
fifoArr
+
"
<br />
"
);
fifoArr.unshift(
"
addFruite
"
);
document.writeln(
"
unshift :
"
+
fifoArr
+
"
<br />
"
);
fifoArr.pop();
document.writeln(
"
pop :
"
+
fifoArr
+
"
<br />
"
);
<
/
script>
<
/
head>
<
body
>
<
span
>
<
/
span><span id="days"><
/
span
>
<
span id
=
"
time
"
><
/
span>
<
/
body>
<
/
html>