检测textarea上的MacOS longpress键弹出窗口

时间:2016-12-26 21:46:58

标签: javascript dom-events

我需要检测textarea上选择弹出键的时间:

enter image description here

图中的这个要清楚。

我目前的发现是,正如我在小提琴中所做的那样注册事件并不能帮助我在弹出窗口打开时找到一些独特的东西。

为什么我需要检测弹出窗口? 因为我在keydown上注册了一个调用e.preventDefault()e.stopImmediatePropagation()的事件。以firefox为例,这种事件处理会阻止弹出窗口完全工作,因此我需要在打开弹出窗口时禁用我的偶数处理程序。



var txt = document.getElementById('test');

txt.addEventListener('compositionupdate', console.log);
txt.addEventListener('compositionstart', console.log);
txt.addEventListener('compositionend', console.log);
txt.addEventListener('input', console.log);
txt.addEventListener('keyup', console.log);
txt.addEventListener('keydown', console.log);
txt.addEventListener('keypress', console.log);

<textarea id="test" ></textarea>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

几个月后,我意识到如何处理它。

这主要是为了检测在fabricjs中使用这个弹出窗口。 我停止使用keyup和keydown,我将所有内容委托给oninput事件。 现在当任何oninput事件触发时,我将textarea中的内容与我的text var进行比较,再加上我检查前后光标的位置,然后检测到这些变化。

效果很好,但不是,弹出窗口无法检测到。

相关问题