WEB开发网
开发学院网页设计JavaScript JavaScript方法和技巧大全——表单 阅读

JavaScript方法和技巧大全——表单

 2010-09-14 13:39:55 来源:WEB开发网   
核心提示: 访问选中的Select1<form name=”myForm”>2 <select name=”mySelect”>3 <option value=”First Choice”>1&

访问选中的Select1<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>

动态增加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>

验证表单字段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>

Tags:JavaScript 方法 技巧

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接