Google Chrome扩展程序中的自动对焦 [英] Auto Focus in Google Chrome extension

查看:136
本文介绍了Google Chrome扩展程序中的自动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个简单的Chrome扩展程序 - 使用表单进行搜索。



当我打开扩展程序时,窗体上没有默认焦点,但需要额外的点击。

焦点假设会发生在popup.html表单上。

现在JavaScript

焦点()方法不起作用,是否有任何其他方式可以为Chrome扩展设置默认焦点?

HTML:

 < input type =textid =mydata/> 

JS:

 的document.getElementById( 'MYDATA')聚焦(); 


解决方案

试试这样:

 < html> 
< head>
< script type =text / javascript>
函数setFocus()
{
document.getElementById(target)。focus();
}
< / script>
< / head>

< body onload =setFocus()>

< input type =textid =targetname =targetsize =25value =/>
< / body>
< / html>

它适用于我。


I made a simple Chrome extension - search with a form.

When I open the extension, there is no default focus on form, but it requires additional click.

Focus is suppose to happen on popup.html form.

Now JavaScript .focus() method didn't work, Is there any other way to set default focus for Chrome extensions?

HTML:

<input type="text" id="mydata"  />

JS:

document.getElementById('mydata').focus();

解决方案

Try something like this:

<html>
<head>
<script type="text/javascript">
function setFocus()
{
     document.getElementById("target").focus();
}
</script>
</head>

<body onload="setFocus()">

<input type="text" id="target" name="target" size="25" value="" />
</body>
</html>

it works for me.

这篇关于Google Chrome扩展程序中的自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆