52,797
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
var obj = {__x: 0};
Object.defineProperty(obj, "x", {
get: function(){
return this.__x;
},
set: function(newValue){
this.__x = newValue;
alert("x更新了:"+this.__x);
},
enumerable : true,
configurable : true
});
</script>
<button onclick="obj.x=1-obj.x">测试变量x变化后触发事件</button>