[英]How can I get the caret position on a contenteditable <button>
So I have a contenteditable button in my webpage I declare like so: 所以我在网页中声明了一个contenteditable按钮,如下所示:
<button id="test" contentEditable="true">This <img src="image..png" /> is a button, click me!</button>
I move the caret around, and I want to find its final location. 我四处移动插入符号,我想找到它的最终位置。 I tried both: 我都尝试过:
but neither of them seems to work :( Any pointers? 但它们似乎都不起作用:(有指针吗?
Update 更新资料
Unfortunately the code from the links below seems to work only with Firefox and not with Chrome (for a button
, div
s work just fine) 不幸的是,以下链接中的代码似乎仅适用于Firefox,不适用于Chrome(对于button
, div
正常工作)
Take a look at these: 看看这些:
Here's a quick and dirty fiddle - it isn't perfect but it might help you get started. 这是一个快速而肮脏的小提琴 -虽然并不完美,但可能会帮助您入门。 I've used code from the blog post at the second link above. 我使用了上面第二个链接中博客文章中的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.