2 way data binding in JavaScript

后端 未结 5 2205
栀梦
栀梦 2020-12-18 09:11

Two-way data binding refers to the ability to bind changes to an object’s properties to changes in the UI, and vice-versa.

Can we achieve 2-way data-binding with Jav

5条回答
  •  感动是毒
    2020-12-18 10:09

    Yes, we can achieve the two way data binding using pure javascript.

    twoWay=function(event) {
      var elem = document.getElementsByClassName(event.currentTarget.className);
      for(var key in elem){
        elem[key].value=event.currentTarget.value;
      }
    }
    

    You can check the jsfiddle.

提交回复
热议问题