标签归档:js.htm

“javascript 脚本‘不支持此属性或方法’错误”主要原因

 

出现“javascript 脚本‘不支持此属性或方法’错误”主要有以下几种原因:

1、方法对应的js函数未定义,如

onclick=”select();”

中,

select()

没有定义,或没有把相应的.js文件包含进来,包含的方法:

<script language=”javascript” src=”xxxx.js”></script>。

 

2、在html中的表单中出现这个问题时,可能是元素的名称和函数的名称相同。这时aspX解释时,会进行把函数当成是元素名,然后认为后面的函数的括号是未定义的函数。如:

 

<script language=”javascript”>

<!–

function ffff()

    … …

end function

–>

</script>

<input name=”aa” type=”button” value=”重置密码” onclick=”ffff();”>

<input name=”ffff” type=”button” value=”sfsdfa” onclick=”ffff();”>

 

上面这个语句通常就会报“对象不支持此属性或方法”的错误。这时,只需要把name=”ffff”改成别的名字或把函数改成别的名字就正常了。

js动态操作表格

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”  
“http://www.w3.org/TR/html4/loose.dtd”> 
<html> 
<head> 
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″> 
<title>js动态操作表格</title> 
<script language=”javascript”> 
 function init(){    
     _table=document.getElementById(“table”);  
     _table.border=”1px”;  
     _table.width=”800px”;  
      
    for(var i=1;i<6;i++){  
         var row=document.createElement(“tr”);    
         row.id=i;  
         for(var j=1;j<6;j++){  
             var cell=document.createElement(“td”);    
             cell.id=i+”/”+j;  
             cell.appendChild(document.createTextNode(“第”+cell.id+”列”));    
             row.appendChild(cell);    
         }  
         document.getElementById(“newbody”).appendChild(row);    
     }  
 }    
   
 function rebulid(){  
    var beginRow=document.getElementById(“beginRow”).value;/*开始行*/  
    var endRow=document.getElementById(“endRow”).value;/*结束行*/  
    /*/*/  
    var beginCol=document.getElementById(“beginCol”).value;/*开始列*/  
    var endCol=document.getElementById(“endCol”).value;/*结束列*/  
      
    var tempCol=beginRow+”/”+beginCol;/*定位要改变属性的列*/  
    alert(tempCol);  
    var td=document.getElementById(tempCol);  
    for(var x=beginRow;x<=endRow;x++){  
        for(var i=beginCol;i<=endCol;i++){  
          if(x==beginRow){  
            document.getElementById(“table”).rows[x].deleteCell(i+1);  
          }  
          else{  
             document.getElementById(“table”).rows[x].deleteCell(i);  
          }  
              
        }  
    }  
    td.rowSpan=(endRow-beginRow)+1;  
}  
 /*添加行,使用appendChild方法*/  
 function addRow(){  
   var length=document.getElementById(“table”).rows.length;  
   /*document.getElementById(“newbody”).insertRow(length);  
   document.getElementById(length+1).setAttribute(“id”,length+2);*/  
   var tr=document.createElement(“tr”);  
   tr.id=length+1;  
   var td=document.createElement(“td”);  
   for(i=1;i<4;i++){  
    td.id=tr.id+”/”+i;  
    td.appendChild(document.createTextNode(“第”+td.id+”列”));  
    tr.appendChild(td);  
     
   }  
  document.getElementById(“newbody”).appendChild(tr);    
 }   
   
 function addRow_withInsert(){  
    var row=document.getElementById(“table”).insertRow(document.getElementById(“table”).rows.length);  
    var rowCount=document.getElementById(“table”).rows.length;  
      
    var countCell=document.getElementById(“table”).rows.item(0).cells.length;  
    for(var i=0;i<countCell;i++){  
      var cell=row.insertCell(i);  
       
      cell.innerHTML=”新”+(rowCount)+”/”+(i+1)+”列”;  
      cell.id=(rowCount)+”/”+(i+1);  
        
      }  
 }  
   
 /*删除行,采用deleteRow(row Index)*/  
 function removeRow(){  
  /* var row=document.getElementById(“2”);   
   var index=row.rowIndex;  
   alert(index);*/  
   document.getElementById(“newbody”).deleteRow(document.getElementById(document.getElementById(“table”).rows.length).rowIndex);   
 }  
   
 /*添加列,采用insertCell(列位置)方法*/  
 function addCell(){  
 /*document.getElementById(“table”).rows.item(0).cells.length  
  用来获得表格的列数  
 */  
    for(var i=0;i<document.getElementById(“table”).rows.length;i++){  
        var cell=document.getElementById(“table”).rows[i].insertCell(2);  
        cell.innerHTML=”第”+(i+1)+”/”+3+”列”;  
          
    }  
 }  
 /*删除列,采用deleteCell(列位置)的方法*/  
 function removeCell(){  
    for(var i=0;i<document.getElementById(“table”).rows.length;i++){  
        document.getElementById(“table”).rows[i].deleteCell(0);  
    }  
}  
</script> 
</head> 
 
<body onLoad=”init();”> 
 
 <table  id=”table” align=”center”>    
     <tbody id=”newbody”></tbody>    
       
 </table>   
  <div> 
    <table width=”800px” border=”1px” align=”center”> 
        <tr><td align=”center”><input type=”button” id=”addRow” name=”addRow” onClick=”addRow();” value=”添加行”/></td><td align=”center”><input type=”button” id=”delRow” name=”delRow” onClick=”removeRow();” value=”删除行”/></td></tr> 
      <tr><td align=”center”><input type=”button” id=”delCell” name=”delCell”  onClick=”removeCell();” value=”删除列”/></td><td align=”center”><input type=”button” id=”addCell” name=”addCell” onClick=” addCell();” value=”添加列”/></td></tr> 
     <tr><td align=”center” colspan=”2″><input type=”button” id=”addRows” name=”addRows”  onClick=”addRow_withInsert();” value=”添加行”/></td></tr> 
    </table> 
 </div> 
 <div> 
    <table width=”800px” border=”1px” align=”center”> 
        <tr><td>从第<input type=”text” id=”beginRow” name=”beginRow”  value=””/>行到<input type=”text”  name=”endRow”  id=”endRow” value=””/>行</td><td rowspan=”2″  id=”test”><input type=”button” name=”hebing” id=”hebing” value=”合并” onClick=”rebulid();”/></td></tr> 
      <tr><td>从第<input type=”text” name=”beginCol” id=”beginCol” value=””/>列到<input type=”text” name=”endCol” id=”endCol” value=””/>列</td></tr> 
    </table> 
 </div> 
</body> 
</html> 

完美兼容IE、FF、Opera的Ajax类支持get、post、自定义回调函数(转载待测)

Js代码

function Ajax(){  
    this.httpXML=false;  
    this.init();  
}  
Ajax.prototype.init=function(){  
    if(window.XMLHttpRequest){  
        this.httpXML=new XMLHttpRequest();   
        if (this.httpXML.overrideMimeType){  
            this.httpXML.overrideMimeType(“text/xml”);   
        }  
    }else if(window.ActiveXObject){  
        try{this.httpXML = new ActiveXObject(“Msxml2.XMLHTTP”);}catch (e){   
             try{this.httpXML = new ActiveXObject(“Microsoft.XMLHTTP”);}catch (e){}   
        }  
    }  
    if(!this.httpXML){  
        window.alert(“can’t create XMLHttpRequest object”);  
        return null;  
    }  
}  
Ajax.prototype.send=function(_method,_url,_data,_callback){  
    this.httpXML.onreadystatechange=function(){  
        if(this.readyState==4&&this.status==200){  
            _callback.call(this,this.responseText);  
        }  
    }  
      
    if (_method.toLowerCase() == “get”){   
         //if(navigator.userAgent.indexOf(“MSIE”)<=0){  
         //     netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);  
         //}  
         this.httpXML.open(_method, _url, true);   
         this.httpXML.send(null);   
    }else if (_method.toLowerCase() == “post”){   
         this.httpXML.open(_method, _url, true);   
         this.httpXML.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);   
         this.httpXML.send(_data);   
    }   
      
}  
 
Ajax.prototype.callback=function(){  
       

function Ajax(){
 this.httpXML=false;
 this.init();
}
Ajax.prototype.init=function(){
 if(window.XMLHttpRequest){
  this.httpXML=new XMLHttpRequest();
  if (this.httpXML.overrideMimeType){
            this.httpXML.overrideMimeType(“text/xml”);
        }
 }else if(window.ActiveXObject){
  try{this.httpXML = new ActiveXObject(“Msxml2.XMLHTTP”);}catch (e){
             try{this.httpXML = new ActiveXObject(“Microsoft.XMLHTTP”);}catch (e){}
        }
 }
 if(!this.httpXML){
  window.alert(“can’t create XMLHttpRequest object”);
  return null;
 }
}
Ajax.prototype.send=function(_method,_url,_data,_callback){
    this.httpXML.onreadystatechange=function(){
        if(this.readyState==4&&this.status==200){
      _callback.call(this,this.responseText);
     }
    }
   
    if (_method.toLowerCase() == “get”){
         //if(navigator.userAgent.indexOf(“MSIE”)<=0){
         //     netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);
         //}
         this.httpXML.open(_method, _url, true);
         this.httpXML.send(null);
    }else if (_method.toLowerCase() == “post”){
         this.httpXML.open(_method, _url, true);
         this.httpXML.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
         this.httpXML.send(_data);
 }
 
}

Ajax.prototype.callback=function(){
 
}

Html代码

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> 
<html xmlns=”http://www.w3.org/1999/xhtml” > 
<head> 
    <title>完美兼容IE、FF、Opera浏览器</title> 
    <script type=”text/javascript” src=”js/ajax.js”></script> 
    <script type=”text/javascript”> 
        function send(){  
            ajax=new Ajax();  
            ajax.send(“get”,”listener/Hajax.ashx”,”post测试请求”,ddd);  
        }  
          
        function ddd(data){  
            alert(data);  
        }  
    </script> 
</head> 
<body> 
    <button onclick=”send()”>测试</button> 
</body> 
</html> 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head>
    <title>完美兼容IE、FF、Opera浏览器</title>
    <script type=”text/javascript” src=”js/ajax.js”></script>
    <script type=”text/javascript”>
        function send(){
            ajax=new Ajax();
            ajax.send(“get”,”listener/Hajax.ashx”,”post测试请求”,ddd);
        }
       
        function ddd(data){
            alert(data);
        }
    </script>
</head>
<body>
    <button onclick=”send()”>测试</button>
</body>
</html>