Listening for variable changes in JavaScript

后端 未结 22 2790
自闭症患者
自闭症患者 2020-11-21 06:57

Is it possible to have an event in JS that fires when the value of a certain variable changes? JQuery is accepted.

22条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 07:10

    AngularJS (I know this is not JQuery, but that might help. [Pure JS is good in theory only]):

    $scope.$watch('data', function(newValue) { ..
    

    where "data" is name of your variable in the scope.

    There is a link to doc.

提交回复
热议问题