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

when the input's width change,the setter function can be triggered in IE11 and FireFox,but it can not work in chrome.

wuxiandiejia
  • 851
  • 1
  • 10
  • 15

1 Answers1

3

Unfortunately, it looks like an old bug in Chrome:

In chrome, unlike other browsers, CSSStyleDeclaration is a function rather than an object.

Related

Community
  • 1
  • 1
Miguel Mota
  • 20,135
  • 5
  • 45
  • 64