JS如何让JS实现类似PHP的__set__get方法?htmlvarusername=document.getElementById('ipt1');alert(username._tipsTxt);alert(username._maxLen);//这些类似_maxLen是不确定的属性javascriptprototype
2 回答

慕斯王
TA贡献1864条经验 获得超2个赞
估计你是想要这个:username.__defineGetter__('_tipsTxt',function(){returnthis.getAttribute('_tipsTxt');});username.__defineSetter__('_tipsTxt',function(txt){this.setAttribute('_tipsTxt',txt);});
添加回答
举报
0/150
提交
取消