<!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=utf-8" />
<title>js demo</title>
<script>
var goodsDiscard=function(){
var $=function(id){
return document.getElementById(id).value;
};
goodsDiscard.prototype={
majon:function(){
alert($("a"));
},
chess:function(){
alert($("b"));
},
fallow:function(){
alert($("c"));
}
};
};
</script>
</head>
<body>
<input type="text" id="a" value="a"><input type="text" id="b" value="b"><input type="text" id="c" value="c">
<a href="javascript:goodsDiscard.majon()">click</a>
</body>
</html>

解决方案 »

  1.   

    总是报goodsDiscard.majon is not a function
      

  2.   

    你要实现什么效果?goodsDiscard.majon()不是这么用的
    majon写在prototype中必须先var a=new goodsDiscard();a.majon()才可以
      

  3.   

    修改成这样就可以了....
    <!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=utf-8" />
    <title>js demo</title>
    <script>
    function GoodsDiscard(){
        var $=function(id){
            return document.getElementById(id).value;
        };
        
    };
    GoodsDiscard.prototype={
    $:function(id){
             return document.getElementById(id).value;
         },
            majon:function(){
                alert(this.$("a"));
            },
            chess:function(){
                alert(this.$("b"));
            },
            fallow:function(){
                alert(this.$("c"));
            }
        };var gd = new GoodsDiscard();
    </script>    
    </head>
    <body>
    <input type="text" id="a" value="a"><input type="text" id="b" value="b"><input type="text" id="c" value="c">
    <a href="javascript:gd.majon()">click</a>
    </body>
    </html>
    你定义的var goodsDiscard =function (){...}不是一个函数对象,而是定义了一个匿名函数,然后赋值给了goodsDiscard
      

  4.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js demo</title>
    <script>
    var goodsDiscard=function(){}
    goodsDiscard.prototype={
    $:function(id){
            return document.getElementById(id).value;
    },
            majon:function(){
                alert(this.$("a"));
            },
            chess:function(){
                alert(this.$("b"));
            },
            fallow:function(){
                alert(this.$("c"));
            }
        };
    var o=new goodsDiscard();
    </script>    
    </head>
    <body>
    <input type="text" id="a" value="a"><input type="text" id="b" value="b"><input type="text" id="c" value="c">
    <a href="javascript:o.majon()">click</a>
    </body>
    </html>
      

  5.   

    是不是非得var gd = new goodsDiscard(); 
      

  6.   


    <!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=utf-8" />
    <title>js demo</title>
    <script>
    var goodsDiscard=function(){
        var $=function(id){
            return document.getElementById(id).value;
        };
        goodsDiscard.prototype={
            majon:function(){
                alert($("a"));
            },
            chess:function(){
                alert($("b"));
            },
            fallow:function(){
                alert($("c"));
            }
        };
    };
    </script>    
    </head>
    <body>
    <input type="text" id="a" value="a"><input type="text" id="b" value="b"><input type="text" id="c" value="c">
    <a href="javascript:new goodsDiscard().majon()">click</a>
    </body>
    </html>