选定的文字和xy坐标 [英] selected text and xy coordinates

查看:107
本文介绍了选定的文字和xy坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何同时获取所选文本和单词的xy坐标?

how to get a selected text and xy coordinates of the word in the same time??

推荐答案

只需在Google上对其进行搜索:

Just googled it:

var txt = "";

if (window.getSelection) {
    txt = window.getSelection();
} else if (document.getSelection) {
    // FireFox 
    txt = document.getSelection();
} else if (document.selection) {
    // IE 6/7 
    txt = document.selection.createRange().text;
}

txt = txt.toString()

没有简单的方法来获取所选文本的X/Y坐标.因为它取决于容器的位置和大小,文本字体,文本布局以及许多其他变量.

There is no simple way to get X/Y coordinates of the selected text. Because it dependes on its container position and size, text font, text layout, and many many other variables.

这篇关于选定的文字和xy坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆