js
1Object.defineProperty(target, 'value',{
2 get : function(){return Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').get.call(target)},
3 set : function(x){
4 console.log(x);
5 Object.getOwnPropertyDescriptor( HTMLInputElement.prototype, 'value' ).set.call( target, x );
6 }
7})
HTMLInputElement.value を監視する - Qiita
みたいなのはいかがでしょう?
コメントを受けて追記
jQueryでの動作サンプル
js
1//元コード
2$(".input1,.input2").focus(function(){
3 $(this).addClass("focus");
4 }).blur(function(){
5 if($(this).val() == ""){
6$(this).removeClass("focus");
7 }else{
8 }
9 });
10
11//想定外部スクリプト
12$('div').on('click', function(){
13 $(".input1,.input2").val(100);
14});
15
16//input監視関数
17var observer = function(_, target){
18 Object.defineProperty(target, 'value',{
19 get : function(){return Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').get.call(target)},
20 set : function(x){
21 $(target).focus();
22 Object.getOwnPropertyDescriptor( HTMLInputElement.prototype, 'value' ).set.call( target, x );
23 }
24 });
25};
26
27//.each()メソッドで監視関数を呼ぶ
28$(".input1,.input2").each( observer );
html
1<input class="input1">
2<input class="input2">
3<div>pref_list</div>
css
1.focus{
2 border:solid 1px red;
3}