As in JS, change style="background-color:



  • I want to change my style="background-color:" directly without calling.

    document.getElementById(this.id).style.backgroundColor = "#ffffff";
    

    a By writing it directly into the context of this, in principle, it works, that is, for example, how it works.

    <input type="text" id="old_id" style="background-color: #ffb3b3" onkeyup="input_fn(this)">
    

    and then do

    function input_fn() {this.id = "new_id"}
    

    And in the chrome everything works perfectly, the id element will change the meaning, but here's a long list of this. style Who's gonna tell you where he's buried?



  • function input_fn(elem){
      elem.style.backgroundColor = "#ffffff";
    }
    <input type="text" id="old_id" style="background-color: #ffb3b3" onkeyup="input_fn(this)">




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2