首页 > Web开发 > 详细

jQuery - Detect value change on hidden input field

时间:2016-01-19 00:13:58      阅读:178      评论:0      收藏:0      [点我收藏+]

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 dont automatically fire the .change() event. So, wherever it is that youre 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

jQuery - Detect value change on hidden input field

原文:http://www.cnblogs.com/wawahaha/p/5140786.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!