是否可以使用JavaScript移动鼠标以使其位于文本输入内?
答案 0 :(得分:21)
我不知道移动实际渲染的鼠标,但是你可以将焦点设置为元素吗?
document.getElementById('the_text_input_id').focus()
答案 1 :(得分:6)
这是一个在输入或文本区域中选择文本的函数:
function textSelect(inp, s, e) {
e = e || s;
if (inp.createTextRange) {
var r = inp.createTextRange();
r.collapse(true);
r.moveEnd('character', e);
r.moveStart('character', s);
r.select();
}else if(inp.setSelectionRange) {
inp.focus();
inp.setSelectionRange(s, e);
}
}
将光标放在第12位:
textSelect(document.getElementById('theInput'), 12);
选择输入字段的一部分:
textSelect(document.getElementById('theInput'), 12, 15);
答案 2 :(得分:5)
答案 3 :(得分:0)
如果他们允许这样的事情,这将是一个巨大的[安全?]问题。
想象一下:你有一个setInterval(function(){moveMouseToTopLeftCorner和alert garbage},1)......
用户将鼠标移动到左上角。然后警报会显示[可以通过输入关闭] ..此时警报会立即再次弹出。
您实际上必须使用键盘打开任务管理器并终止浏览器> _>
然而,ActiveX可能是可能的[虽然那只IE浏览器......而且很愚蠢]