在文本框中获取选定的文本 [英] Get selected text in a textbox
本文介绍了在文本框中获取选定的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得HTML < input>
文本框元素中所选文本的字符位置? window.getSelection()
在文本框内不起作用。
How can I get the character positions of the selected text in an HTML <input>
textbox element? window.getSelection()
doesn't work inside textboxes.
推荐答案
如果您使用的是jQuery,请查看jQuery Caret插件: jCaret
If you're using jQuery, take a look at the jQuery Caret plugin: jCaret
// Get start pos in intput box with id="box1"
$("#box1").caret().start
// Get end pos
$("#box1").caret().end
// Get selected text
$("#box1").caret().text
这篇关于在文本框中获取选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文