<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<button id="btn">click</button>
<script type="text/javascript">
var btn = document.getElementById("btn");
alert(btn.toString());
</script>
</body>
</html>没问题啊

解决方案 »

  1.   

    JS里面没有重载,后面的函数会覆盖前面的函数,比如
    function show()

       alert(1);
    }
    function show(num)
    {
       alert(3);
    }都是调用后面那个函数,前面那个就没了
      

  2.   


    <input type="text" id="inp" />
    <script>
    var inp = document.getElementById('inp');

    inp.toString = function(){
    return this.tagName;
    }
    alert(inp.toString()); // INPUT
    </script>
      

  3.   

    抱歉,我不应该说“重载 overload”,应该说“覆写 override”下面是一个覆写的例子:// 覆写 Date 的 toString 方法
    Date.prototype.toString = function() {
        return this.getYear()+"-"+this.getMonth()+"-"+this.getDate();
    }Date 对象的默认toString()输出是: [object Date]
    覆写后toString()的输出是:2008-9-22
      

  4.   

    好象dom对象没办法重写,下面是ff的测试,没办法重写
    IE不知道怎么获取通用的DOM对象
    <html> 
    <head> 
    <script>
    window.onload=function(){
     if(typeof(HTMLElement)!="undefined")
      HTMLElement.prototype.toMyString=function(){//增加一个新方法
        if((this.tagName=="INPUT"&&this.type=="button")||this.tagName=="BUTTON"){
          return "重写Button的toString()";
        }
        return this.toString();
      }
      
      HTMLElement.prototype.toString=function(){//重写toString,不过不起作用
        if((this.tagName=="INPUT"&&this.type=="button")||this.tagName=="BUTTON"){
          return "重写Button的toString()";
        }
        return this.toString();
      }
    }</script> 
    </head> 
    <body> 
    <input type="button" value="btn1" onclick="alert(this.toString())"/> 
    <input type="button" value="btn2"  onclick="alert(this.toString())"/> 
    <input type="text" onclick="alert(this.toMyString())"/> 
    <button onclick="alert(this.toMyString())">btn3</button>
    </body> 
    </html>
      

  5.   

    多谢showbo的代码!在firefox下如此写可以,IE下还没有办法:// input 控件的toString()重载
    HTMLInputElement.prototype.toString = function() 
    {
      return "id(" + this.id + ")name(" + this.name + ")type("+ this.type + ")value("+ this.value+")";
    }