实时监听输入框值变化的完美方案:oninput & onpropertychange

来源:互联网 发布:mac怎么下网页视频 编辑:程序博客网 时间:2024/06/06 02:54

oninput 是 HTML5 的标准事件,对于检测 textarea, input:text, input:password 和 input:search 这几个元素通过用户界面发生的内容变化非常有用,在内容修改后立即被触发,不像 onchange 事件需要失去焦点才触发。


只需要绑定事件即可。

$('textarea').bind('input propertychange'function() {
    $('.msg').html($(this).val().length + ' characters');
});

0 0
原创粉丝点击