jquery focus命令不能从chrome命令行工作 [英] jquery focus command doesn't work from chrome command line

查看:176
本文介绍了jquery focus命令不能从chrome命令行工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有如下所述的文字页面。调用 $(#target)。focus();头文件中的 $()部分中的工作得很好。我还可以将该命令绑定到更加实际的页面中的事件。不过,如果我打开chrome控制台并键入 $(#target)。focus(); 它不会改变焦点。如果我运行 $(#target).val(something); 它会改变屏幕上的值,但它不适用于焦点。



显然这不是一个关键问题,但我真的很好奇为什么会发生这种情况。任何人有想法?

 < html> 
< head>
< script src =jquery-1.9.1.js>< / script>
< script>
$(function(){
$(#target)。focus();
});
< / script>
< / head>

< body>
< input id =targettype =text>
< / body>
< / html>


解决方案

您会意识到,点击Chrome控制台时,它会从当前页面上的任何输入或textarea控件中窃取焦点,反之亦然。这是因为Chrome控制台实际上是使用与任何其他HTML页面相同的HTML控件实现的,只是具有特殊属性,例如阻止Chrome以递归方式检查Chrome控制台。



当您在Chrome控制台中输入命令时,即在Chrome控制台的输入控件中输入命令时,它将保持焦点。 Chrome工程师可能会选择以不同的方式实施它,但在大多数情况下,用户希望在发出命令后继续在Chrome控制台中输入内容,因此没有任何命令会从控制台释放焦点。


If I have a text page as described below. The call to $("#target").focus(); in the $() section in the header works just fine. I can also bind that command to events in a more realistic page.

However, if I open the chrome console and type $("#target").focus(); it does not change focus. If I run $("#target").val("something"); it changes the value on the screen, but it does not work with focus.

Obviously this isn't a critical problem, but I am really curious why this happens. Anyone have an idea?

<html>
  <head>
    <script src="jquery-1.9.1.js"></script>
    <script>
      $(function(){
         $("#target").focus();
      });
    </script>
  </head>

 <body>
   <input id="target" type="text">
 </body>
</html>

解决方案

You will realize that when clicking on the Chrome console, it will steal focus from any input or textarea control on the current page, and vice versa. That's because the Chrome console actually is implemented using the same HTML controls as any other HTML page, just with special properties which, for instance, prevent Chrome from inspecting the Chrome console recursively.

When you type a command in the Chrome console, i.e. in the input control that is part of the Chrome console, it will keep the focus. The Chrome engineers might have chosen to implement it differently, but in most cases the user will want to continue typing in the Chrome console after firing a command, so no command will release focus from the console.

这篇关于jquery focus命令不能从chrome命令行工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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