var chkother=document.getElementsByTagName("input");   //获取页面上input标签的集合
   for (var i=0;i<chkother.length;i++)  {   //遍历input标签    if( chkother[i].type =="text")      //判断是否是文本框
         
      {
      chkother[i].Attribute.Add("onfocus","c=ojbNode.style.background;ojbNode.style.background='#ECF9FC';")
      chkother[i].Attribute.Add("onblur","ojbNode.style.background=c;")
      }
}我是想在加载的时候给文本框控件添加焦点事件,可是弄的晕晕的后面这两个添加事件怎么提示对象为空呢,不明白,代码问题在哪里,有知道的朋友说下

解决方案 »

  1.   


     var chkother=document.getElementsByTagName("input"); 
       for (var i=0;i<chkother.length;i++)  {     if( chkother[i].type =="text")   
             
          {
          chkother[i].Attribute.Add("onfocus","c=chkother[i].style.background;chkother[i].style.background='#ECF9FC';")
          chkother[i].Attribute.Add("onblur","chkother[i].style.background=c;")
          }
    }
    }是这个,哪里有问题呢?
      

  2.   

    var f1 = function () { 
      c=chkother[i].style.background;
      chkother[i].style.background = '#ECF9FC';
    };
    var f2 = functon () { 
      chkother[i].style.background = c;
    };
    if(window.attachEvent)
    {
      chkother[i].attachEvent('onfoucs', f1);
      chkother[i].attachEvent('onblur', f2);
    }
    else
    {
      chkother[i].addEventListener('foucs', f1);
      chkother[i].addEventListener('blur', f2);
    }