面向对象(this的问题二)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>

function zgz()
{
var _this=this
this.a=5;

document.getElementById('btn').onclick=function(){

_this.show();

}
}

zgz.prototype.show=function(){

alert(this.a)

}

window.onload=function(){

new zgz();

}


</script>
</head>

<body>
<input id="btn" type="button" value="按钮">
</body>
</html>

posted @ 2015-02-06 20:35  菜园子丶  阅读(118)  评论(0编辑  收藏  举报