41 创建幻灯片

1: <script language=”JavaScript”>
2: var p_w_picpathList = new Array;
3: p_w_picpathList[0] = new Image;
4: p_w_picpathList[0].src = “p_w_picpath1.jpg”;
5: p_w_picpathList[1] = new Image;
6: p_w_picpathList[1].src = “p_w_picpath2.jpg”;
7: p_w_picpathList[2] = new Image;
8: p_w_picpathList[2].src = “p_w_picpath3.jpg”;
9: p_w_picpathList[3] = new Image;
10: p_w_picpathList[3].src = “p_w_picpath4.jpg”;
11: function slideShow(p_w_picpathNumber) {
12: document.slideShow.src = p_w_picpathList[p_w_picpathNumber].src;
13: p_w_picpathNumber += 1;
14: if (p_w_picpathNumber < p_w_picpathList.length) {
15: window.setTimeout(“slideShow(“ + p_w_picpathNumber + “)”,3000);
16: }
17: }
18: </script>
19: </head>
20: <body onLoad=”slideShow(0)”>
21: <img src="/”p_w_picpath1.jpg"” width=100 name=”slideShow”>


42 随机广告图片

1: <script language=”JavaScript”>
2: var p_w_picpathList = new Array;
3: p_w_picpathList[0] = “p_w_picpath1.jpg”;
4: p_w_picpathList[1] = “p_w_picpath2.jpg”;
5: p_w_picpathList[2] = “p_w_picpath3.jpg”;
6: p_w_picpathList[3] = “p_w_picpath4.jpg”;
7: var urlList = new Array;
8: urlList[0] = “
[url]http://some.host/[/url] ”;
9: urlList[1] = “
[url]http://another.host/[/url] ”;
10: urlList[2] = “
[url]http://somewhere.else/[/url] ”;
11: urlList[3] = “
[url]http://right.here/[/url] ”;
12: var p_w_picpathChoice = Math.floor(Math.random() * p_w_picpathList.length);
13: document.write(‘<a href=”’ + urlList[p_w_picpathChoice] + ‘“><img src=”’ + p_w_picpathList[p_w_picpathChoice] + ‘“></a>’);
14: </script>

JavaScript就这么回事4:表单


还是先继续写完JS就这么回事系列吧~
43 表单构成

1: <form method=”post” action=”target.html” name=”thisForm”>
2: <input type=”text” name=”myText”>
3: <select name=”mySelect”>
4: <option value=”1”>First Choice</option>
5: <option value=”2”>Second Choice</option>
6: </select>
7: <br>
8: <input type=”submit” value=”Submit Me”>
9: </form>


44 访问表单中的文本框内容

1: <form name=”myForm”>
2: <input type=”text” name=”myText”>
3: </form>
4: <a href='#'>Check Text Field</a>


45 动态复制文本框内容

1: <form name=”myForm”>
2: Enter some Text: <input type=”text” name=”myText”><br>
3: Copy Text: <input type=”text” name=”copyText”>
4: </form>
5: <a href=”#” onClick=”document.myForm.copyText.value =
6: document.myForm.myText.value;”>Copy Text Field</a>


46 侦测文本框的变化

1: <form name=”myForm”>
2: Enter some Text: <input type=”text” name=”myText” onChange=”alert(this.value);”>
3: </form>


47 访问选中的Select

1: <form name=”myForm”>
2: <select name=”mySelect”>
3: <option value=”First Choice”>1</option>
4: <option value=”Second Choice”>2</option>
5: <option value=”Third Choice”>3</option>
6: </select>
7: </form>
8: <a href='#'>Check Selection List</a>


48 动态增加Select项

1: <form name=”myForm”>
2: <select name=”mySelect”>
3: <option value=”First Choice”>1</option>
4: <option value=”Second Choice”>2</option>
5: </select>
6: </form>
7: <script language=”JavaScript”>
8: document.myForm.mySelect.length++;
9: document.myForm.mySelect.options[document.myForm.mySelect.length - 1].text = “3”;
10: document.myForm.mySelect.options[document.myForm.mySelect.length - 1].value = “Third Choice”;
11: </script>


49 验证表单字段

1: <script language=”JavaScript”>
2: function checkField(field) {
3: if (field.value == “”) {
4: window.alert(“You must enter a value in the field”);
5: field.focus();
6: }
7: }
8: </script>
9: <form name=”myForm” action=”target.html”>
10: Text Field: <input type=”text” name=”myField”onBlur=”checkField(this)”>
11: <br><input type=”submit”>
12: </form>


50 验证Select项

1: function checkList(selection) {
2: if (selection.length == 0) {
3: window.alert(“You must make a selection from the list.”);
4: return false;
5: }
6: return true;
7: }