JavaScript表单

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

44 访问表单中的文本框内容
1 None.gif < form name = ”myForm” >
2 None.gif  < input type = ”text” name = ”myText” >
3 None.gif </ form >
4 None.gif < a href = '#' onClick = 'window.alert(document.myForm.myText.value);' > Check Text Field </ a >  

45 动态复制文本框内容
1 None.gif < form name = ”myForm” >
2 None.gif Enter some Text:  < input type = ”text” name = ”myText” >< br >
3 None.gif Copy Text:  < input type = ”text” name = ”copyText” >
4 None.gif </ form >
5 None.gif  < a href = ”#” onClick = ”document.myForm.copyText.value  =  document.myForm.myText.value;” > Copy Text Field </ a >  

46 侦测文本框的变化
1 None.gif < form name = ”myForm” >
2 None.gif Enter some Text:  < input type = ”text” name = ”myText” onChange = ”alert( this .value);” >
3 None.gif </ form >  

47 访问选中的Select
 1 None.gif < form name = ”myForm” >
 2 None.gif  < select name = ”mySelect” >
 3 None.gif   < option value = ”First Choice” > 1 </ option >
 4 None.gif   < option value = ”Second Choice” > 2 </ option >
 5 None.gif   < option value = ”Third Choice” > 3 </ option >
 6 None.gif  </ select >
 7 None.gif </ form >
 8 None.gif < a href = '#' onClick = 'alert(document.myForm.mySelect.value);' > Check Selection List </ a >  

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

49 验证表单字段
 1 None.gif < script language = ”JavaScript” >
 2 ExpandedBlockStart.gifContractedBlock.gif function  checkField(field)  dot.gif
 3ExpandedSubBlockStart.gifContractedSubBlock.gif if (field.value == “”) dot.gif
 4InBlock.gif   window.alert(“You must enter a value in the field”);
 5InBlock.gif   field.focus();
 6ExpandedSubBlockEnd.gif }

 7ExpandedBlockEnd.gif}

 8 None.gif </ script >
 9 None.gif < form name = ”myForm” action = ”target.html” >
10 None.gif  Text Field:  < input type = ”text” name = ”myField”onBlur = ”checkField( this )” >
11 None.gif   < br >< input type = ”submit” >
12 None.gif </ form >  

50 验证Select项
1 ExpandedBlockStart.gif ContractedBlock.gif function  checkList(selection)  dot.gif
2ExpandedSubBlockStart.gifContractedSubBlock.gif if (selection.length == 0dot.gif
3InBlock.gif   window.alert(“You must make a selection from the list.”);
4InBlock.gif   return false;
5ExpandedSubBlockEnd.gif }

6InBlock.gif return true;
7ExpandedBlockEnd.gif}

51 动态改变表单的action
1 None.gif < form name = ”myForm” action = ”login.html” >
2 None.gif Username:  < input type = ”text” name = ”username” >< br >
3 None.gif Password:  < input type = ”password” name = ”password” >< br >
4 None.gif  < input type = ”button” value = ”Login” onClick = this .form.submit();” >
5 None.gif  < input type = ”button” value = ”Register” onClick = this .form.action  =  ‘register.html’;  this .form.submit();” >
6 None.gif  < input type = ”button” value = ”Retrieve Password” onClick = this .form.action  =  ‘password.html’;  this .form.submit();” >
7 None.gif </ form >  

52 使用图像按钮
1 None.gif < form name = ”myForm” action = ”login.html” >
2 None.gif Username:  < input type = ”text” name = ”username” >< br >
3 None.gif Password:  < input type = ”password”name = ”password” >< br >
4 None.gif  < input type = ”image” src = " /”login.gif " ” value = ”Login” >
5 None.gif </ form >

53 表单数据的加密
 1 None.gif < SCRIPT LANGUAGE = 'JavaScript' >
 2 None.gif <!--
 3 ExpandedBlockStart.gifContractedBlock.gif  function  encrypt(item)  dot.gif
 4InBlock.gif   var newItem = '';
 5ExpandedSubBlockStart.gifContractedSubBlock.gif   for (i=0; i < item.length; i++dot.gif
 6InBlock.gif     newItem += item.charCodeAt(i) + '.';
 7ExpandedSubBlockEnd.gif   }

 8InBlock.gif   return newItem;
 9ExpandedBlockEnd.gif }

10 None.gif
11 ExpandedBlockStart.gifContractedBlock.gif  function  encryptForm(myForm)  dot.gif
12InBlock.gif   for (i=0; i < myForm.elements.length; i++)   
13ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif
14InBlock.gif     myForm.elements[i].value = encrypt(myForm.elements[i].value);
15ExpandedSubBlockEnd.gif   }

16ExpandedBlockEnd.gif }

17 None.gif 
18 None.gif // -->
19 None.gif </ SCRIPT >
20 None.gif  < form name = 'myForm' onSubmit = 'encryptForm( this ); window.alert( this .myField.value);' >
21 None.gif Enter Some Text:  < input type = text name = myField >< input type = submit >
22 None.gif </ form >   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值