简体   繁体   中英

jQuery function working in Chrome, but not in IE

Company doesn't use HTML5, created the following workaround to allow use of the maxlength attribute for textareas. This works for Google Chrome, but doesn't work in Internet Explorer, any input would be appreciated, thanks! EDIT: I am using jQuery 1.6.2 and IE 11 UPDATE: After further troubleshooting, I have determined that IE is completely ignoring the jQuery function

$('textarea[maxlength]').keydown(function(){
    var limit = parseInt($(this.attr('maxlength')));
    var text = $(this).val();
    if (text.length > limit) {
      var new_text = text.substr(0, limit);
      $(this).val(new_text);
    }
});

You have a typo in the code, with the parentheses in the parseInt argument. It should be:

    var limit = parseInt($(this).attr('maxlength'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM