日期:2014-05-17 浏览次数:20568 次
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function test() {
this.value = 1;
this.get = function () { alert(this.value); }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="a" value="a" />
<input type="text" id="b" value="b" />
</div>
<script>
var t = new test;
document.getElementById("a").onclick = function () {t.get() };
document.getElementById("b").onclick= t.get;
</script>
</form>
</body>
</html>
------解决方案--------------------
你可以看下这个精华贴:点击
------解决方案--------------------
var t = new test; //t为test方法
document.getElementById("a").onclick = function () {t.get() };//点击后,执行t.get()脚本
document.getElementById("b").onclick= t.get;//取get的值