setter 函数无法在 chrome 中触发
The setter function can not be triggered in chrome
<input type="text" id="test">
<script type="text/javascript">
var test=document.getElementById("test");
Object.defineProperty(test.style,"width",{
set:function(){
alert(1);
}
});
test.onfocus=function(){
test.style.width="120px";
}
</script>
当输入宽度改变时,setter功能在IE11和FireFox中可以触发,但在chrome中不可用。
不幸的是,它看起来像是 Chrome 中的一个老错误:
In chrome, unlike other browsers, CSSStyleDeclaration is a function rather than an object.
- 90335 - It seems that 'Object.defineProperty' does not work on 'CSSStyleDeclaration.prototype' property.
- 89697 - CSSStyleDeclaration report incorrect descriptor
相关
- Override property CSSStyleDeclaration.textShadow?
<input type="text" id="test">
<script type="text/javascript">
var test=document.getElementById("test");
Object.defineProperty(test.style,"width",{
set:function(){
alert(1);
}
});
test.onfocus=function(){
test.style.width="120px";
}
</script>
当输入宽度改变时,setter功能在IE11和FireFox中可以触发,但在chrome中不可用。
不幸的是,它看起来像是 Chrome 中的一个老错误:
In chrome, unlike other browsers, CSSStyleDeclaration is a function rather than an object.
- 90335 - It seems that 'Object.defineProperty' does not work on 'CSSStyleDeclaration.prototype' property.
- 89697 - CSSStyleDeclaration report incorrect descriptor
相关
- Override property CSSStyleDeclaration.textShadow?