码迷,mamicode.com
首页 > Web开发 > 详细

jQuery - Detect value change on hidden input field

时间:2016-01-19 00:14:32      阅读:508      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!