开发者

Undo function not firing after keyup on textual input

开发者 https://www.devze.com 2023-02-18 06:48 出处:网络
I have a simple script showing the character count for a text input element or a textarea element. $(\"input[type=text],textarea\").keyup(function(){

I have a simple script showing the character count for a text input element or a textarea element.

$("input[type=text],textarea").keyup(function(){

    var currentLength = ($(this).val().length);
    var maximum = 100;  
    var spanLimit = $("span[name=Limit]");

    spanLimit.html("("+ currentLength + " of " + maximum + ")");
});

While the script performs its function, I noticed that the user loses the ab开发者_JAVA百科ility to undo his/her typing with either Ctrl+Z or the right click menu option. If I comment out the following line, the undo function is not lost:

spanLimit.html("("+ currentLength + " of " + maximum + ")");

Is there any way to not lose the undo stack after performing DOM manipulation?

P.S. This behavior is visible when using IE8


You forgot a quote in var spanLimit = $("span[name=Limit]);.

It should be var spanLimit = $("span[name=Limit]");

0

精彩评论

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