简体   繁体   English

隐藏输入更改时触发 onchange 事件

[英]Fire onchange event when hidden input changes

I have various inputs that I want to set a dirty flag.我有各种要设置脏标志的输入。

However the onchange event does not fire if these inputs are modified by javascript.但是,如果这些输入被 javascript 修改,则不会触发 onchange 事件。
Many of the inputs are customised data entry moodules written by many other people and have hidden input and javascript UI layer to modify the hidden input.许多输入是由许多其他人编写的自定义数据输入模块,并具有隐藏输入和 javascript UI 层来修改隐藏输入。

I want to detect when these hidden inputs change.我想检测这些隐藏输入何时发生变化。 (without modifying the original author's script) (不修改原作者的剧本)
Also normal inputs do not trigger the 'onchange' event until 'blur' but I could get round this with the onkeyup event.正常输入在“模糊”之前不会触发“onchange”事件,但我可以通过 onkeyup 事件来解决这个问题。

I know this is an old question, but I had the same one, and I found the answer here: What event can be captured when an HTML hidden input value is set / changed我知道这是一个老问题,但我有同样的问题,我在这里找到了答案: What event can be capture when an HTML hidden input value is set / changed

EDIT: "Check out ' domattrmodified ' event.编辑: “查看‘ domattrmodified ’事件。

Just a thought, because you dont want to modify the original authors script.只是一个想法,因为您不想修改原始作者的脚本。

Could you maybe monitor those fields?你能监控那些领域吗?

/*
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]);
        }


    }
})();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM