在Chrome中聚焦
On Focus in Chrome
我正在检查我的项目的浏览器兼容性。我正在调用一个按钮的OnFocus
事件的函数。除了在Chrome中,所有其他浏览器都会执行该代码,但如果我在文本字段的OnFocus
事件上调用相同的函数,则意味着它也会在Chrome中执行。有人能帮我解决这个问题吗?如何在按钮的onfocus
事件上调用函数(应该在Chrome中执行)?
以下是使用两种方法监视focus
事件的示例:通过addEventListener
函数和通过onfocus
元素属性。
<script>
function onfocused(ev){
document.getElementById('si').textContent=ev.target.id;
}
onload=function(){
document.getElementById('einput').addEventListener('focus', onfocused, false);
document.getElementById('ebutton').addEventListener('focus', onfocused, false);
};
</script>
<div id=si>?</div>
<br />
<br />
Via addEventListener:
<input id=einput type=button value="einput" />
<button id=ebutton>ebutton</button>
<br />
<br />
Via onfocus attribute:
<input id=iinput type=button value="iinput" onfocus="onfocused(event)" />
<button id=ibutton onfocus="onfocused(event)">ibutton</button>
相关文章:
- Chrome WebKitGetUserMedia
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- 在chrome.tabs.onCreated之后加载HTML页面
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- chrome扩展更改主机/域警告
- Chrome开发工具(如何知道我在调用哪个javascript对象)
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- Google/html5语音识别JavaScript SDK Chrome网络工具包SpeechRecognition
- 激活chrome上的chrome.notifications对象
- 在Chrome中聚焦
- 让我的 html 输入数字字段在滚轮上更改,即使它们在 Chrome 中没有聚焦
- 在Chrome扩展程序“弹出窗口”上打开/聚焦
- 当窗口聚焦时,也就是打开时,可以阅读Chrome
- 如何自动聚焦浏览器选项卡时,点击浏览器通知在Chrome
- 捕获日语输入在非聚焦的输入元素在Chrome
- JS生成的不可编辑的DIV不能在Chrome中聚焦(和模糊),直到静态HTML编码可以
- 在google chrome扩展中使用javascript聚焦文本框