我正在尝试创建一个脚本来检测一个人何时完成突出显示文本。为此,我在包含 p 的 div 中有一个 onclick 事件,其中包含文本。如果您单击黄色空间中的任意位置,则单击事件上应该会出现警报框。如果您突出显示文本的一部分(但不是一直到文本末尾!)该事件将触发。
当您突出显示并包括最后一个单词“text”时,就会出现该错误。该事件不会触发。
我可以在 Chrome 和 Safari 中复制它,但在 Firefox 中似乎可以正常工作。没有测试过IE。
<html>
<head>
<style>
div{background-color:#FFFF00}
</style>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
function mouseClicked()
{
alert("mouseClicked");
}
</script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
</div>
<div onClick='mouseClicked()'>
<p>Try to highlight this text</p>
</div>
</body>
</html>
有任何想法吗?谢谢, Kshanti
编辑:刚刚发现它适用于这样使用的 onmouseup 事件:document.onmouseup=mouseClicked;
仍然很奇怪,它不适用于 onclick。