Chapter6-JavaScript常用表单操作_第1页
Chapter6-JavaScript常用表单操作_第2页
Chapter6-JavaScript常用表单操作_第3页
Chapter6-JavaScript常用表单操作_第4页
Chapter6-JavaScript常用表单操作_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第六章

JavaScript常用表单操作智翔集团文本框不允许粘贴<inputtype="text"name="txtName"onpaste="returnfalse"oncontextmenu="returnfalse"

/>得到焦点后全选<inputname="txt1"type="text"onfocus="this.select()"/>回车键可以让光标移到下一个输入框<inputtype="text"name="txtName"onkeydown="if(event.keyCode==13)event.keyCode=9"

/>文本框只允许输入数字<scripttype="text/javascript">varre=/^[0-9.-]*$/;varstr='';functionchecknum(obj){

if(re.test(obj.value)==false){

obj.value=str;

}else{

str=obj.value;}}</script><inputtype="text"name="txtName"onpropertychange="checknum(this)">Checkbox全选Checkbox<script>functioncheckall(formname,checkname,thestate){ varel_collection=eval("document.forms."+formname+"."+checkname) for(c=0;c<el_collection.length;c++) el_collection[c].checked=thestate}</script><formname="test"><inputtype="checkbox"name="v1">Peter<br/><inputtype="checkbox"name="v1">Jane<br/><inputtype="checkbox"name="v1">George<br/><ahref="javascript:checkall('test','v1',true)">CheckAll</a><br/><ahref="javascript:checkall('test','v1',false)">UncheckAll</a></form>下拉框<formaction=""method="post"name="f1"><selectname="cmb1"style="width:100px"><optionvalue="1">湖北</option><optionvalue="2">湖南</option><optionvalue="3">广东</option></select><inputtype="button"name="but1"onclick="javascript:alert(f1b1.options[f1b1.selectedIndex].value)“value="显示选择项的值"><inputtype="button"name="but2"onclick="javascript:alert(f1b1.options[f1b1.selectedIndex].text)"value="显示选择项的显示内容"><inputtype="button"name="but3"onclick="javascript:alert(f1b1.options.length)"value="显示有多少选择项"><inputtype="button"name="but4"onclick="javascript:f1b1.options[3].selected=true"value="选择广东"></form>列表框判断指定值是否包含在列表中functionjsSelectIsExitItem(objSelect,objItemValue){//objSelect:列表框名称//objItemValue:要查找的值

varisExit=false;for(vari=0;i<objSelect.options.length;i++){if(objSelect.options[i].value==objItemValue){isExit=true;break;}}returnisExit;}列表框向select选项中参加一个ItemfunctionjsAddItemToSelect(objSelect,objItemText,objItemValue){if(jsSelectIsExitItem(objSelect,objItemValue)){

//判断是否存在

}else{varvarItem=newOption(objItemText,objItemValue);objSelect.options.add(varItem);}}列表框从select选项中删除一个ItemfunctionjsRemoveItemFromSelect(objSelect,objItemValue){

if(jsSelectIsExitItem(objSelect,objItemValue)){for(vari=0;i<objSelect.options.length;i++){if(objSelect.options[i].value==objItemValue){objSelect.options.remove(i);break;}}}else{

//该select中不存在该项

}}列表框删除select中选中的项functionjsRemoveSelectedItemFromSelect(objSelect){varlength=objSelect.options.length-1;for(vari=length;i>=0;i--){if(objSelect[i].selected==true){objSelect.options[i]=null;}}}列表框修改select选项中value="paraValue"的text为"paraText"functionjsUpdateItemToSelect(objSelect,objItemText,objItemValue){

if(jsSelectIsExitItem(objSelect,objItemValue)){for(vari=0;i<objSelect.options.length;i++){if(objSelect.options[i].value==objItemValue){objSelect.options[i].text=objItemText;break;}}}else{

//不存在

}}列表框设置select中text="paraText"的第一个Item为选中"paraText"functionjsSelectItemByValue(objSelect,objItemText){varisExit=false;for(vari=0;i<objSelect.options.length;i++){if(objSelect.options[i].text==objItemText){objSelect.options[i].selected=true;isExit=true;break;}}if(isExit){

//成功选中

}else{

//该select中不存在该项

}}列表框二个列表框之间选择列表框带Checkbox的列表框列表框二级联动三级联动带查看大图的Image表格动态增加行动态创立表格表格表格隔行换色、鼠标经过变色功能实现检查表格被选行是否包含指定的值表格带排序功能的Table带筛选功能的Table表单遍历表单上所有元素

functionallfrom(){

for(i=0;i<f1.length;i++){

alert(f1[i].name);}

}表单根据ID属性定位元素document.getElementById('txt2').value根据Name属性定位元素document.getElementsByName('txt1')[0].value根据元素类型定位元素vardocnObj=document.getElementsByTagName("input");for(i=0;i<docnObj.length;i++){vardocnObj=document.getElementsBy

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论