jQuery 'input' event

后端 未结 8 752
执念已碎
执念已碎 2020-11-22 08:53

I\'ve never heard of an event in jQuery called input till I saw this jsfiddle.

Do you know why it\'s working? Is it an alias for keyup or s

8条回答
  •  庸人自扰
    2020-11-22 09:09

    oninput event is very useful to track input fields changes.

    However it is not supported in IE version < 9. But older IE versions has its own proprietary event onpropertychange that does the same as oninput.

    So you can use it this way:

    $(':input').on('input propertychange');
    

    To have a full crossbrowser support.

    Since the propertychange can be triggered for ANY property change, for example, the disabled property is changed, then you want to do include this:

    $(':input').on('propertychange input', function (e) {
        var valueChanged = false;
    
        if (e.type=='propertychange') {
            valueChanged = e.originalEvent.propertyName=='value';
        } else {
            valueChanged = true;
        }
        if (valueChanged) {
            /* Code goes here */
        }
    });
    

提交回复
热议问题