14 分割字符串
<script language=”JavaScript”>
<!--
var myVariable = “a,b,c,d”;
var stringArray = myVariable.split(“,”);
document.write(stringArray[0]);
document.write(stringArray[1]);
document.write(stringArray[2]);
document.write(stringArray[3]);
// -->
</script>
15 弹出警告信息
<script language=”JavaScript”>
<!--
window.alert(“Hello”);
// -->
</script>
16 弹出确认框
<script language=”JavaScript”>
<!--
var result = window.confirm(“Click OK to continue”);
// -->
</script>
17 定义函数
<script language=”JavaScript”>
<!--
function multiple(number1,number2) {
var result = number1 * number2;
return result;
}
// -->
</script>
18 调用JS函数
<a href=”#” onClick=”functionName()”>Link text</a>
<a href="/”javascript:functionName"()”>Link text</a>
19 在页面加载完成后执行函数
<body onLoad=”functionName();”>
Body of the page
</body>
20 条件判断
<script>
<!--
var userChoice = window.confirm(“Choose OK or Cancel”);
var result = (userChoice == true) ? “OK” : “Cancel”;
document.write(result);
// -->
</script>
21 指定次数循环
<script>
<!--
var myArray = new Array(3);
myArray[0] = “Item 0”;
myArray[1] = “Item 1”;
myArray[2] = “Item 2”;
for (i = 0; i < myArray.length; i++) {
document.write(myArray + “<br>”);
}
// -->
</script>
22 设定将来执行
<script>
<!--
function hello() {
window.alert(“Hello”);
}
window.setTimeout(“hello()”,5000);
// -->
</script>
23 定时执行函数
<script>
<!--
function hello() {
window.alert(“Hello”);
window.setTimeout(“hello()”,5000);
}
window.setTimeout(“hello()”,5000);
// -->
</script>
24 取消定时执行
<script>
<!--
function hello() {
window.alert(“Hello”);
}
var myTimeout = window.setTimeout(“hello()”,5000);
window.clearTimeout(myTimeout);
// -->
</script>
25 在页面卸载时候执行函数
<body onUnload=”functionName();”>
Body of the page
</body>
