• jQuery


    You can simply use the below function, You can also change the type element.

    $("input[type=hidden]").bind("change", function() {
           alert($(this).val()); 
     });
    Changes in value to hidden elements don't automatically fire the .change() event. So, wherever it is that you're setting that value, you also have to tell jQuery to trigger it.
    
    HTML 
    <div id="message"></div>
    <input type="hidden" id="testChange" value="0"  />    

    JAVASCRIPT

    var $message = $('#message');
    var $testChange = $('#testChange');
    var i = 1;
    
    function updateChange() {
        $message.html($message.html() + '<p>Changed to ' + $testChange.val() + '</p>');
    }
    
    $testChange.on('change', updateChange);
    
    setInterval(function() {
        $testChange.val(++i).trigger('change');; 
        console.log("value changed" +$testChange.val());
    }, 3000);
    
    updateChange();

    should work as expected.

    http://jsfiddle.net/7CM6k/3/

    转载:http://stackoverflow.com/questions/6533087/jquery-detect-value-change-on-hidden-input-field

  • 相关阅读:
    设计模式
    刷新所有视图存储过程
    js杨辉三角控制台输出
    2018申请淘宝客AppKey
    w3c标准 dom对象 事件冒泡和事件捕获
    promise原理
    vue virtual Dom
    css学习
    seo优化
    新概念学习
  • 原文地址:https://www.cnblogs.com/wawahaha/p/5140786.html
Copyright © 2020-2023  润新知