日期:2014-05-17  浏览次数:20646 次

html表单单个reset功能实现

表单的reset,无非是吧表单域的值还原成了defaultValue的值。

如果想实现全部表单的reset,则可以遍历所有的表单,然后将value值设置为defaultValue即可。

this.value = this.defaultValue;

?

为form表单添加reset功能:

?? function _3080(_3090){
??? ??? $("input,select,textarea",_3090).each(function(){
??? ??? ??? if($(this).hasClass("combo-text") || $(this).hasClass("combo-value")){
??? ??? ??? ??? return;
??? ??? ??? }
??? ??? ??? if($.fn.combobox && $(this).hasClass("combobox-f")){$(this).combobox("reset");return;}
??? ??? ??? if($.fn.combotree && $(this).hasClass("combotree-f")){$(this).combotree("reset");return;}
??? ??? ??? if($.fn.combogrid && $(this).hasClass("combogrid-f")){$(this).combogrid("reset");return;}
??? ??? ??? if($.fn.datebox && $(this).hasClass("datebox-f")){$(this).datebox("reset");return;}
??? ??? ??? if($.fn.datetimebox && $(this).hasClass("datetimebox-f")){$(this).datetimebox("reset");return;}
??? ??? ???
??? ??? ??? if($.fn.combo && $(this).hasClass("combo-f")){$(this).combo("reset");return;}
??? ??? ??? var t=this.type,tag=this.tagName.toLowerCase();
??? ??? ??? if(t=="text"||t=="hidden"||t=="password"||tag=="textarea"){
??? ??? ??? ??? this.value=this.defaultValue;
??? ??? ??? }else{
??? ??? ??? ??? if(t=="checkbox"||t=="radio"){
??? ??? ??? ??? ??? this.checked=this.defaultValue;
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? if(tag=="select"){
??? ??? ??? ??? ??? ??? this.selectedIndex=this.defaultValue;
??? ??? ??? ??? ??? }
??? ??? ??? ??? }
??? ??? ??? }
??? ??? });
??? };

?