刚来一个新公司  看代码时看的我有的纠结    
比如代码中是这样写的document.getElementById("txtTest").printView();
这个printView()  我始终么想得到怎么实现  怎么实现呢    必须是 document.getElementById("txtTest").方法  的形式  
在线等   只要贴代码  测试过的

解决方案 »

  1.   

    非ie可以很容易的实现(你确定ie下也可以  ie下先的给这个元素设置printView方法  才能用)
      

  2.   

    非ie下<!DOCTYPE html>  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>google map</title>  
      
    </head>  
    <body>  
    <div id='txtTest'></div>
    </body>  
    <script type="text/javascript">
    HTMLElement.prototype = {
    printView : function(){
    this.innerHTML = '123123123123'
    }
    }
    window.onload = function(){
    document.getElementById("txtTest").printView();
    }
    </script>
    </html>  ie下只能每次给每个元素加了   
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>test</title>
      <script language="javascript">
        HTMLInputElement.prototype.printView = function(){alert(0);};
      </script></style></head>
    <body onload="setInitFoucs()">
    <input type="text" id="test"/>
    <input type="button" value="test" onclick="document.getElementById('test').printView();"/>
    </body>
    </html>
      

  4.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>test</title>
      <script language="javascript">
      HTMLInputElement.prototype.printView = function(){alert(0);};
      </script></style></head>
    <body>
    <input type="text" id="test"/>
    <input type="button" value="test" onclick="document.getElementById('test').printView();"/>
    </body>
    </html>
      

  5.   

    嗯   firefox和360测试通过   ie呢  具体点怎么实现  document.getElementById("txtTest").prototype.printView = function(){alert(0);};
    这种方式不行啊