我寫了一個jQuery字符計數器,它在我輸入時起作用,但在粘貼文本時不起作用。 該功能在粘貼時執行,但計數不會更改。我不確定val()
函數是否正確或與DOM同步。有任何想法嗎?jQuery - 字符計數器不適用於粘貼事件
counter = function() {
$j("strong#status-field-char-counter").text($j("#Panel1messagesmessage").val().length);
alert('event');
};
$j("textarea").keyup(counter);
$j("textarea").bind('paste', counter);
$j("#Panel1messagesmessage").bind('copy', counter);
$j("#Panel1messagesmessage").bind('delete', counter);
'粘貼' 是不是在http://docs.jquery.com/Events/bind ......也被列爲一個有效的事件,你可以添加事件作爲第二個參數'bind()'作爲一個字符串,每個事件用空格'$('#selector')分隔。bind('click mouseover',function(){})' – artlung 2009-11-02 15:48:58
這裏是解決不支持的事件的SO問題:http://stackoverflow.com/questions/237254/how-do-you-handle-oncut-oncopy-and-onpaste-in-jquery – artlung 2009-11-02 15:52:17