我有各种输入,我想设置脏标志。
但是,如果这些输入被javascript修改,则onchange事件不会触发 许多输入是由许多其他人编写的自定义数据输入模块,并具有隐藏的输入和javascript UI层来修改隐藏的输入。
我想检测这些隐藏的输入何时发生变化。 (不修改原作者的剧本)
正常输入也不会触发'onchange'事件,直到'模糊',但我可以通过onkeyup事件来解决这个问题。
答案 0 :(得分:0)
编辑:“查看' domattrmodified '活动。
只是一个想法,因为你不想修改原作者脚本。
您可以监控这些字段吗?
/*
Very simple monitor utility.
Monitor what?
This monitors any dom element which has a "value" attribute.
This was created to monitor hidden fields that were altered via javascript.
Fields that had values changed via javascript did not trigger the "change" event.
This is a solution to that problem.
Usage:
Monitor.monitor('element_id',(function) callback);
Monitor.demonitor('element_id');
*/
var Monitor = (function(){
var inputs = [];
return {
monitor:function(input_id,callback){
var previous_value = "";
function go (){
current_value = document.getElementById(input_id).value;
if(previous_value !== current_value){
callback();
}
previous_value = document.getElementById(input_id).value;
}
inputs[input_id] = setInterval(go,200);
},
demonitor:function(input_id){
clearInterval(inputs[input_id]);
}
}
})();
答案 1 :(得分:0)
我知道这是一个老问题,但我有同样的问题,我在这里找到答案:What event can be captured when an HTML hidden input value is set / changed