如题:
现在实现一个搜索功能,为了保持搜索数据,用jstl保持的问题来了,重置时清空问题,reset不能用,自己写了一个方法 function doC() {
document.getElementById("form1").reset();
var s1 = document.getElementById("sel_company").value;
if(document.all("sel_company")!=null ) { s1 = ""; }
问题:if里面的判断怎么写ps:因为有多个页面的多个条件,都放在一个文件里面,直接赋值""的话,是按顺序执行的,当页面没有这个字段就停住了。望高手解答,网上找了半天,都不好用。sel_company为搜索条件,还有很多,input里面 id  name都是它。

解决方案 »

  1.   

    条件没控制好啊,应该是:
    if (document.getElementById("sel_company")) document.getElementById("sel_company").value = "";
    不过,还是利用Tag来写个通用函数来处理吧:
      var objs = document.getElementsByTag("input"); // 返回所有的<Input>标签对象
    然后循环处理objs就行了。
      

  2.   

    var s1 = document.getElementById("sel_company").value;
     if(document.all("sel_company")!=null ) { s1 = ""; }
    你把文本框的值复制给了 s1 
    又将空置赋值给了 s1 
    但是你没有给你的文本框值赋值
    这样就可以了
    var s1 = document.getElementById("sel_company").value;
     if(document.all("sel_company")!=null ) 
    { document.getElementById("sel_company").value = ""; }
      

  3.   

    function doC() {
    document.getElementById("form1").reset();if(document.all("sel_company")!=null ) { 
     document.getElementById("sel_company").value = "";
    }