问题描述
我在我的iMac上使用Firefox 2.0.0.16和Safari 3.1.2中的HTML5 < canvas>
(我在Windows上的Firefox 3.0中也尝试过了,也没有效果。)标签如下:
I'm using the HTML5 <canvas>
element in Firefox 2.0.0.16 and in Safari 3.1.2, both on my iMac. (I've tried this in Firefox 3.0 on Windows as well, also to no avail.) The tag looks like this:
<td>
<canvas id="display"
width="500px"
height="500px">
</canvas>
</td>
我有一个按钮来激活一些与画布交互的功能。该按钮的 onclick()
事件调用一个函数。在该函数中,我有以下行:
I have a button to "activate" some functionality that interacts with the canvas. That button's onclick()
event calls a function. In that function I have the following line:
document.getElementById("display").focus();
这不起作用。 Firebug报告没有错误。但重点仍然是它在那里。我可以点击画布或选项卡朝向画布,焦点将从其他元素中消失,但显然从来没有被画布获得(画布的 onfocus()
事件从来没有火灾)。
This does not work. Firebug reports no error. But the focus still remains where it was. I can click on the canvas or tab towards the canvas and focus will be lost from the other elements, but apparently never be gained on by the canvas (The canvas's onfocus()
event never fires).
我觉得这很奇怪。是不是画布根本不能得到焦点,或者我在这里缺少的东西?
I find this odd. Is it that the canvas simply cannot get focus, or am I missing something here? Any insight would be appreciated.
谢谢。
推荐答案
画布a标签索引:
<canvas id="display"
width="500px"
height="500px"
tabindex="1">
</canvas>
这篇关于如何将焦点设置为HTML5 canvas元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!