面向对象(this的问题二)

时间:2023-03-08 16:26:28

<!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>