<!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>
<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>
解决方案 »
- IE6下,js改变className无效的问题
- 如何把json_encode($araAry)转换的php二维数组,动态赋值给js下拉列表!
- 如何正确使用Object.extend?在线求解
- js+flash的幻灯片广告怎么替换图片?
- 各位各位, Look Here! 请帮帮忙哦!!
- 哎。。。菜鸟就是菜鸟改一下就不能用了,苦恼中
- js函数返回值的问题
- 分享一个JS的调试方法,对远程调试JS最爽
- 用JavaScript可以设置当前网页不显示菜单栏和地址栏吗?
- jQuery在ie9下不兼容怎么回事
- css控制分辨率???
- 给页面中所有input添加click事件监视器,在页面前面宏观添加,不要用unload,不要在每个input上直接添加onclick,怎么做?
majon写在prototype中必须先var a=new goodsDiscard();a.majon()才可以
<!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
<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>
<!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>