两种方法都有不好的地方,这个东东是用一个ASP.net页面上面的,用清空搜索条件,把条件都重置到页面刚好LOAD出来的时候的状态document.formName.reset()
这个方法只能够在第一次的时候起作用,当搜索之后这个Reset键就失效了window.location.reload();
这个会造成整个页面Reload,并不需要这么做吧,会加重服务器负担,这个功能在客户端完成就行了。
这个方法只能够在第一次的时候起作用,当搜索之后这个Reset键就失效了window.location.reload();
这个会造成整个页面Reload,并不需要这么做吧,会加重服务器负担,这个功能在客户端完成就行了。
* This function is to clear a form (or a container of implements such as table,tr ..).
* JK
* formObj:the checked form
* exceptObjName:the name of whitch need not be checked;
* For example:clearForm(document.frm,"ACheckbox,BRadio,CSelect");
*/
function clearForm(formObj,exceptObjName)
{
if(formObj==null) formObj=document.forms[0];
if(exceptObjName==null) exceptObjName=="";
var selectObjs=formObj.getElementsByTagName("SELECT");//For Select Obj
for(var i=0;i<selectObjs.length;i++)
{
if((selectObjs[i].name=="")||(eval("/(^|,)"+selectObjs[i].name+"(,|$)/g").test(exceptObjName))) continue;
selectObjs[i].value="";
} var inputObjs=formObj.getElementsByTagName("INPUT");//For Input Obj
for(var i=0;i<inputObjs.length;i++)
{
if((inputObjs[i].name=="")||(eval("/(^|,)"+inputObjs[i].name+"(,|$)/g").test(exceptObjName))) continue;
if(inputObjs[i].type.toUpperCase()=="TEXT") inputObjs[i].value="";
else if((inputObjs[i].type.toUpperCase()=="RADIO")||(inputObjs[i].type.toUpperCase()=="CHECKBOX"))
inputObjs[i].checked=false;
}
var textareaObjs=formObj.getElementsByTagName("TEXTAREA");//For textarea Obj
for(var i=0;i<textareaObjs.length;i++)
{
if((textareaObjs[i].name=="")||(eval("/(^|,)"+textareaObjs[i].name+"(,|$)/g").test(exceptObjName))) continue;
textareaObjs[i].value="";
}
}
document.getElementById("select").options[0].selected = true;当然写个程序遍历表单中所有的INPUT和SELECT都这样设置,比一个一个手工做简单~~~呵呵,多写两行代码的事情~~~
冤枉啊!
没有一棒子打死呢
还给它留了个出气的地方:第二个参数exceptObjName就是让使用者设置不处理的对象,
如果发生了“万一它页面初始时比如多选框是选中的”
那就这样调用:clearForm(document.formObj,"ASelect");