我使用此代码
var textarea = $('#mess');
var typingStatus = $('#typing_on');
var lastTypedTime = new Date(0); // it's 01/01/1970, actually some time in the past
var typingDelayMillis = 5000; // how long user can "think about his spelling" before we show "No one is typing -blank space." message
function refreshTypingStatus() {
if (!textarea.is(':focus') || textarea.val() == '' || new Date().getTime() - lastTypedTime.getTime() > typingDelayMillis) {
typingStatus.html('No one is typing -blank space.');
} else {
typingStatus.html('User is typing...');
}
}
function updateLastTypedTime() {
lastTypedTime = new Date();
}
setInterval(refreshTypingStatus, 100);
textarea.keypress(updateLastTypedTime);
textarea.blur(refreshTypingStatus);
如果我使用此文本区域,显示的代码将起作用
<textarea id="mess" rows="2" style="display: none;"></textarea>
可以,但是我在文本区域中使用了一个div框,
<div class="emojionearea-editor" contenteditable="true" placeholder="Scrivi il messaggio qui, e invialo in chat..." tabindex="0" dir="ltr" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"></div>
您能帮我弄清楚如何使其适用于textarea divos吗?如果我使用div不能正常工作
答案 0 :(得分:0)
我有一个关于Codepen的工作演示。 我更改的行是 if(!textarea.is(':focus')|| textarea.val()==''||新的Date()。getTime()-lastTypedTime.getTime()>输入DelayMillis)
TextArea具有价值,但是由于您使用div时我使用了文本,因此html可能同样适用。
https://codepen.io/anon/pen/jgVQZW?editors=1111
if (!textarea.is(':focus') || textarea.text() == '' || new Date().getTime() - lastTypedTime.getTime() > typingDelayMillis)