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

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

 2010-09-14 13:39:55 来源:WEB开发网   
核心提示: 验证Select项1function checkList(selection) {2 if (selection.length == 0) {3 window.alert(“You must make a selection from the list.”);4 r

验证Select项

1function 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}

动态改变表单的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>

使用图像按钮

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=http://tech.ddvip.com/2009-02/"/”login.gif"” value=”Login”>
5</form>

表单数据的加密

1<SCRIPT LANGUAGE='JavaScript'>
2 function encrypt(item) { 
3  var newItem = '';
4   for (i=0; i < item.length; i++) { 
5    newItem += item.charCodeAt(i) + '.';
6   }
7  return newItem;
8 }
9 function encryptForm(myForm) { 
10  for (i=0; i < myForm.elements.length; i++) { 
11     myForm.elements[i].value = encrypt(myForm.elements[i].value);
12  }
13}
14</SCRIPT>
15<form name='myForm' onSubmit='encryptForm(this); window.alert(this.myField.value);'>
16 Enter Some Text: <input type=text name=myField><input type=submit>
17</form>

上一页  1 2 3 

Tags:JavaScript 方法 技巧

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