参考这个
http://blog.csdn.net/avon520/archive/2008/06/16/2553197.aspx

解决方案 »

  1.   

    先写一个js文件 TextJs.js
    function TextJs(){
        this.a = function(){
            return "这个是A";
        }
        this.b = function(){
            return "这个是B";
        }
        
        this.c = function(str){//带参数
            return str;
        }
        
        this.d = "ddddd";//同时可以有属性
    }创建一个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>无标题页</title><script type="text/javascript" language="jscript" src="js/TextJs.js"></script>
    <script type="text/javascript">
    function init(){
        var obj = new TextJs();//创建对象(也可带上参数)
        var textA = obj.a();//调用对象的方法a()
        var textB = obj.b();
        var textC = obj.c("我是C");//带参数
        var textD = obj.d;//属性
        alert(textA);//输出
        alert(textB);
        alert(textC);
        alert(textD);
    }
    </script>
    </head>
    <body onload="init()">
        <div>
        
        </div>
    </body>
    </html>试试这个(obj 为该对象  .js文件路径要写对)当然js文件内容也可以写到html页面中