删除文本时IE中的jQuery .live('input)无法正常工作 [英] jQuery .live('input) in IE not working when removing text

查看:140
本文介绍了删除文本时IE中的jQuery .live('input)无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于此问题根据以下内容淡入/淡出文本计数器的值

我有以下标记:-

<textarea id="TextBox1"></textarea>
<br/>
<span id="validator" style="display:none"></span>

和以下jQuery:-

and the following jQuery:-

jQuery('#TextBox1').live('input', function() {

    var charLength = $(this).val().length;

    $('#validator').html(charLength + ' of 250 characters used');
    $('#validator').fadeInOrOut(!! charLength);

    if ($(this).val().length > 250) {
        $('#validator').html('<strong>You may only have up to 250 characters !</strong>');
    }

});

jQuery.fn.fadeInOrOut = function(status) {
    return status ? this.fadeIn() : this.fadeOut();
}; 

这一切在Firefox中都可以正常工作,但是在IE中,尤其是从文本区域中删除文本时,.live()事件似乎没有被触发.

This all works fine in Firefox, but in IE, specifically when removing text from the textarea the .live() event doesn't seem to get fired.

这里有一个小提琴来演示上面的内容,如果您在Firefox中加载功能正常,请在IE中加载并向文本区域添加一些文本,然后使用退格键删除一些文本.

There is a fiddle here that demonstrates the above, if you load in Firefox functionality works fine, load in IE and add some text to the textarea, then remove some text using the backspace key.

http://jsfiddle.net/general_exception/CsXU8/

EDIT 似乎有所不同,该错误仍然存​​在.

EDIT using on doesent seem to make a difference, the bug still remains.

推荐答案

根据您的jQuery版本,使用. on()而不是.live(),而不是绑定到input,只需使用keyup来捕获事件

Depending on your version of jQuery, use .on() instead of .live(), and instead of binding to input, just use keyup to catch the event

jQuery('#TextBox1').on('keyup', function() { });

这篇关于删除文本时IE中的jQuery .live('input)无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆