开发者

can I use blur in a hidden field, jquery

can I use blur in a hidden field in jquery? if not, how can I track cha开发者_Python百科nges in a hidden field


Hidden field is hidden, it won't be visible to a user to change something. Only page author/script can change its value and if that is the case, you can use the change event to track changes.

$('#hidden_id').change(function(){
  alert('Changed Value: ' + $(this).val());
});


NO, you can't in it's normal behavior.

The onchange event occurs when a control loses the input focus (blur) and its value has been modified since gaining focus.

http://www.w3.org/TR/html401/interact/scripts.html#adef-onchange

But you can do it as Sarfraz suggested. Add onchange event then explicitly trigger it every time you change the value of the hidden typed input


The 'change()' event handler doesn't work on hidden input fields. What you can do instead is something along these lines (untested!):

function hiddenOnChange(elem, function) {
    if ($(elem).val()!=$(elem).getAttr('oldVal')) {
        function;
    }
    $(elem).attr('oldVal', $(elem).val());

    window.setTimeout(function(){hiddenOnchange(elem, function);}, 100);
}

Call this function with your hidden input field and the onchange function. It re-creates the onchange function by comparing the field's "current" value with a previously stored value. If nothing is changed, it re-checks in 100 msecs; If something did change, it will execute your function (I hope ;))

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜