铬扩展弹出文本区焦点 [英] chrome extension popup textarea focus

查看:78
本文介绍了铬扩展弹出文本区焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在弹出菜单中有类似的东西。

在弹出菜单中,我无法在焦点() .js:

  $(document).ready(function(){
console.log($(# ('。'));
$('textarea')。focus();
$('。container')。css(color,red);
} );

我在popup.html中引用它:

 < html> 
< head>

< link rel =stylesheethref =css / content.csstype =text / css>

< script type =text / javascriptsrc =js / lib / jquery.js>< / script>
< script type =text / javascriptsrc =js / popup.js>< / script>
< / head>
< body>
< div class =container>
< textarea name =newText>< / textarea>
< / div>
< / body>

css-change有效,focus()不会!



当我调试弹出窗口并输入$('textarea')。focus();在控制台中,它的工作原理。
在ready-callback中添加的事件已成功绑定。



任何帮助都非常感谢!

解决方案

我仍然不知道,为什么焦点不在第一位,而是一个简单的超时工作:)

  setTimeout(function(){
$('#moped-text')。focus();
},500);


It seems that i cannot call focus() on a textarea of my chrome extensions popup when it gets opened / after ondomready.

i have something like that in popup.js :

$(document).ready(function () {
   console.log($("#moped-text"));
   $('textarea').focus();   
   $('.container').css("color", "red");
});

i reference it in popup.html like that:

<html>
  <head>

    <link rel="stylesheet" href="css/content.css" type="text/css">

    <script type="text/javascript" src="js/lib/jquery.js"></script>
    <script type="text/javascript" src="js/popup.js"></script>
  </head>
 <body>
       <div class="container">
            <textarea name="newText"></textarea>
       </div>     
 </body>

The css-change works, the focus() does not!

When i debug the popup and type $('textarea').focus(); in the console, it works. Also events added inside the ready-callback are bound successfully.

Any help highly appreciated!

解决方案

i still don't know, why the focus is not set at the first place, but a simple timeout does the job :)

setTimeout(function() {
  $('#moped-text').focus();
}, 500);

这篇关于铬扩展弹出文本区焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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