js 使用方法與函數(shù) 總結(jié)
更新時間:2009年05月17日 18:19:18 作者:
js使用方法小結(jié),比較不錯,無論是新手,還是老手都是不錯的。
43 表單構(gòu)成
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 訪問表單中的文本框內(nèi)容
1: <form name="myForm">
2: <input type="text" name="myText">
3: </form>
4: <a href='#' onClick='window.alert(document.myForm.myText.value);'>Check Text Field</a>
45 動態(tài)復(fù)制文本框內(nèi)容
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='#' onClick='alert(document.myForm.mySelect.value);'>Check Selection List</a>
48 動態(tài)增加Select項(xiàng)
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 驗(yàn)證表單字段
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 驗(yàn)證Select項(xiàng)
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: }
51 動態(tài)改變表單的action
1: <form name="myForm" action="login.html">
2: Username: <input type="text" name="username"><br>
3: Password: <input type="password" name="password"><br>
4: <input type="button" value="Login" onClick="this.form.submit();">
5: <input type="button" value="Register" onClick="this.form.action = ‘register.html'; this.form.submit();">
6: <input type="button" value="Retrieve Password" onClick="this.form.action = ‘password.html'; this.form.submit();">
7: </form>
52 使用圖像按鈕
1: <form name="myForm" action="login.html">
2: Username: <input type="text" name="username"><br>
3: Password: <input type="password"name="password"><br>
4: <input type="image" src="/"login.gif"" value="Login">
5: </form>
6:
53 表單數(shù)據(jù)的加密
1: <SCRIPT LANGUAGE='JavaScript'>
2: <!--
3: function encrypt(item) {
4: var newItem = '';
5: for (i=0; i < item.length; i++) {
6: newItem += item.charCodeAt(i) + '.';
7: }
8: return newItem;
9: }
10: function encryptForm(myForm) {
11: for (i=0; i < myForm.elements.length; i++) {
12: myForm.elements[i].value = encrypt(myForm.elements[i].value);
13: }
14: }
15:
16: //-->
17: </SCRIPT>
18: <form name='myForm' onSubmit='encryptForm(this); window.alert(this.myField.value);'>
19: Enter Some Text: <input type=text name=myField><input type=submit>
20: </form>
相關(guān)文章
『JavaScript』限制Input只能輸入數(shù)字實(shí)現(xiàn)思路及代碼
一個文字方塊必須限制只能輸入數(shù)字(或是小數(shù)點(diǎn))并且要支援 IE 和 Firefox,接下來為大家介紹下如何解決這個需求2013-04-04
javascript 正則表達(dá)式相關(guān)應(yīng)介紹
javascript 中幾個與正則表達(dá)式相關(guān)的應(yīng)用,本文將詳細(xì)介紹,需要的朋友可以參考下2012-11-11
JS對象與json字符串相互轉(zhuǎn)換實(shí)現(xiàn)方法示例
這篇文章主要介紹了JS對象與json字符串相互轉(zhuǎn)換實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了js對象與json字符串相互轉(zhuǎn)換的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-06-06
JS實(shí)現(xiàn)禁止用戶使用Ctrl+鼠標(biāo)滾輪縮放網(wǎng)頁的方法
這篇文章主要介紹了JS實(shí)現(xiàn)禁止用戶使用Ctrl+鼠標(biāo)滾輪縮放網(wǎng)頁的方法,涉及javascript頁面元素與事件相關(guān)操作技巧,需要的朋友可以參考下2017-04-04
JS實(shí)現(xiàn)獲取當(dāng)前所在周的周六、周日示例分析
這篇文章主要介紹了JS實(shí)現(xiàn)獲取當(dāng)前所在周的周六、周日,結(jié)合具體實(shí)例形式分析了javascript針對日期時間的獲取與計(jì)算相關(guān)操作技巧,需要的朋友可以參考下2019-05-05
JS數(shù)組操作大全對象數(shù)組根據(jù)某個相同的字段分組
這篇文章主要介紹了JS數(shù)組操作大全對象數(shù)組根據(jù)某個相同的字段分組,需要注意的是,在開發(fā)過程這種數(shù)組的處理函數(shù),應(yīng)當(dāng)被編寫到項(xiàng)目的公共工具函數(shù)庫中全局調(diào)用,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11
cnblogs csdn 代碼運(yùn)行框?qū)崿F(xiàn)代碼
大家用cnblogs,csdn博客發(fā)布技術(shù)文檔的時候,可以用下面的代碼實(shí)現(xiàn)運(yùn)行功能。當(dāng)然大家看了源碼就會發(fā)現(xiàn)其實(shí)方法還有很多。有更好的方法就發(fā)布一下啊。2009-11-11

