【发布时间】:2011-05-09 02:05:14
【问题描述】:
你好,我的代码有问题.. 为什么它不起作用..??? 我的代码有问题吗?
function selectWord() {
var select = window.getSelection();
if (select.getBoundingClientRect) {
var rect = select.getBoundingClientRect ();
x = rect.left;
y = rect.top;
w = rect.right - rect.left;
h = rect.bottom - rect.top;
alert (" Left: " + x + "\n Top: " + y + "\n Width: " + w + "\n Height: " + h);
}
else {
alert ("Your browser does not support!");
}
}
谢谢
【问题讨论】:
-
“它不起作用”是什么意思?你期望有什么输出,你得到什么?
-
你有 4 个隐含的全局变量 (x, y, w, h),更正一下。另外,为什么在函数名称和调用运算符之间放置空格?使用
foo()而不是foo ()。
标签: javascript mozilla selectedtext