禁用左键单击(用于心理实验),但 IE 中的焦点会发生变化。如何预防?
我正在对网页设计进行一些心理实验,我想禁用两次鼠标点击。 (请忽略可用性问题。我知道这些问题。我故意这样做是为了我的心理实验。)
到目前为止,我成功地禁用了 Firefox、Chrome 和 Safari 中的点击。然而,在 IE 中,当我单击鼠标左键时,焦点仍然会更改为我单击的位置。我想停止这种行为(即焦点保留在我单击之前的位置)。系统是否产生警报并不重要,因为无论如何我都会使用警报。
如果你们中的一些人能帮助我,我将不胜感激。 请注意,我无法使用 JQuery。我的实验工具不能很好地处理JQuery。
<html>
<head>
</head>
<body>
<div>
<select>
<option> aa </option>
</select>
</div>
<div>
<select>
<option> aa </option>
</select>
</div>
<script type="text/javascript">
function mousehandler(){
alert("For the purpose of psych experiment, you can't use mouse.");
return false;
}
document.oncontextmenu = mousehandler;
document.onmousedown = mousehandler;
</script>
</body>
</html>
I am conducting some Psych experiment on web design, and I want to disable both mouse clicks. (Please ignore usability issues. I know about them. I intentionally do this for the purpose of my psych experiment.)
So far I succeeded disabling both clicks in Firefox, Chrome, and Safari. In IE, however, when I left click, focus still changes to the place I clicked. I want to stop this behavior (i.e. focus remains the place before I click). It doesn't matter whether the system produces alert or not, because I'm going to use alert anyway.
I appreciate if some of you can help me.
Please note that I CAN'T use JQuery. My experiment tool cannot handle JQuery well.
<html>
<head>
</head>
<body>
<div>
<select>
<option> aa </option>
</select>
</div>
<div>
<select>
<option> aa </option>
</select>
</div>
<script type="text/javascript">
function mousehandler(){
alert("For the purpose of psych experiment, you can't use mouse.");
return false;
}
document.oncontextmenu = mousehandler;
document.onmousedown = mousehandler;
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道为什么 IE8 会这样做,但如果您将第二个选择设置为在页面加载时获得焦点,那么在您的
mousehandler()
函数中添加setTimeout(function(){document .getElementsByTagName("select")[1].focus();},1);
在返回 false 之前,您可以给第二个选择它的焦点。然后看来它从未失去对第一个选择的关注。setTimeout()
的原因是因为没有它,第一个选择将获得焦点。编辑: jsFiddle 示例
Not sure why IE8 is doing this but if you are setting the second select to have focus when the page loads, then in your
mousehandler()
function if you addsetTimeout(function(){document.getElementsByTagName("select")[1].focus();},1);
before the return false you can give the second select it's focus back. It then appears that it never lost focus to the first select.The reason for
setTimeout()
is because without it the first select will gain focus.EDIT: jsFiddle example