1
<
script language
=
”JavaScript”
>
2
var
myURL
=
document.URL;
3
window.alert(myURL);
4
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27 动态输出HTML
1
<
script language
=
”JavaScript”
>
2
document.write(“
<
p
>
Here’s some information about
this
document:
</
p
>
”);
3
document.write(“
<
ul
>
”);
4
document.write(“
<
li
>
Referring Document: “
+
document.referrer
+
“
</
li
>
”);
5
document.write(“
<
li
>
Domain: “
+
document.domain
+
“
</
li
>
”);
6
document.write(“
<
li
>
URL: “
+
document.URL
+
“
</
li
>
”);
7
document.write(“
</
ul
>
”);
8
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
28 输出换行
1
document.writeln(“
<
strong
>
a
</
strong
>
”);
2
document.writeln(“b”);
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
29 输出日期
1
<
script language
=
”JavaScript”
>
2
var
thisDate
=
new
Date();
3
document.write(thisDate.toString());
4
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
30 指定日期的时区
1
<
script language
=
”JavaScript”
>
2
var
myOffset
=
-
2
;
3
var
currentDate
=
new
Date();
4
var
userOffset
=
currentDate.getTimezoneOffset()
/
60
;
5
var
timeZoneDifference
=
userOffset
-
myOffset;
6
currentDate.setHours(currentDate.getHours()
+
timeZoneDifference);
7
document.write(“The time and date
in
Central Europe is: “
+
currentDate.toLocaleString());
8
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
31 设置日期输出格式
1
<
script language
=
”JavaScript”
>
2
var
thisDate
=
new
Date();
3
var
thisTimeString
=
thisDate.getHours()
+
“:”
+
thisDate.getMinutes();
4
var
thisDateString
=
thisDate.getFullYear()
+
“
/
”
+
thisDate.getMonth()
+
“
/
”
+
thisDate.getDate();
5
document.write(thisTimeString
+
“ on “
+
thisDateString);
6
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32 读取URL参数
1
<
script language
=
”JavaScript”
>
2
var
urlParts
=
document.URL.split(“
?
”);
3
var
parameterParts
=
urlParts[
1
].split(“
&
”);
4![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
for
(i
=
0
; i
<
parameterParts.length; i
++
)
{
5
var pairParts = parameterParts[i].split(“=”);
6
var pairName = pairParts[0];
7
var pairValue = pairParts[1];
8
document.write(pairName + “ :“ +pairValue );
9
}
10
</
script
>
你还以为HTML是无状态的么?
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
5
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![ExpandedBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
10
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
33 打开一个新的document对象
1
<
script language
=
”JavaScript”
>
2![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function
newDocument()
{
3
document.open();
4
document.write(“<p>This is a New Document.</p>”);
5
document.close();
6
}
7
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
3
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![ExpandedBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34 页面跳转
1
<
script language
=
”JavaScript”
>
2
window.location
=
"http://www.livebaby.cn";
3
</
script
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
35 添加网页加载进度窗口
1
<
html
>
2
<
head
>
3
<
script language
=
'javaScript'
>
4
var
placeHolder
=
window.open('holder.html','placeholder','width
=
200
,height
=
200
');
5
</
script
>
6
<
title
>
The Main Page
</
title
>
7
</
head
>
8
<
body onLoad
=
'placeHolder.close()'
>
9
<
p
>
This is the main page
</
p
>
10
</
body
>
11
</
html
>
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)