简体   繁体   English

从url开始的制表顺序

[英]Tab order starting from url

Is it possible to somehow make it so that when you are in the url bar of your browser and you press TAB you go to the first inputfield on your page and not your bookmarks or something else? 是否有可能做到这一点,以便当您在浏览器的网址栏中并按TAB键时,转到页面的第一个输入字段,而不是书签或其他内容?

Using focus() could somehow be a workaround but it's not what I am looking for. 使用focus()在某种程度上可能是一种解决方法,但这不是我想要的。

So focus is in URL bar, user presses TAB, focus goes to the first input field :) 因此,焦点位于URL栏中,用户按TAB键,焦点转到第一个输入字段:)

Thanks in advance. 提前致谢。

This isn't possible with jQuery as you are trying to change the "tab index" of your browser software. 对于jQuery,这是不可能的,因为您正在尝试更改浏览器软件的“标签索引”。 This is outside the contraints of jQuery. 这超出了jQuery的约束。 Ie. 就是 Its outside of the DOM . 它在DOM之外。

If there is a way of changing it, I doubt it is possible to do this cross-browser, and would probably be only possible for your particular instance of your browser software. 如果有更改的方法,我怀疑是否可以执行此跨浏览器,并且可能仅对您的浏览器软件的特定实例可行。

Yes, you can do that by setting tabindex attributes , like you set any other attributes. 是的,您可以通过设置tabindex属性来实现 ,就像设置其他属性一样。 If you wish to do that in scripting, and not directly in HTML, you just use the attr() method. 如果您希望通过脚本而不是直接在HTML中进行操作,则只需使用attr()方法。

The details depend on the page structure and desired behavior, and you need to understand how the tabindex attributes specify the tabbing order. 详细信息取决于页面结构和所需的行为,并且您需要了解tabindex属性如何指定制表顺序。 Consider a very simple case, where you have just a <div class=nav> containing navigational links and another part of the page containing input fields. 考虑一个非常简单的情况,您只有一个<div class=nav>包含导航链接,而页面的另一部分则包含input字段。 Suppose you want the fields to be tabbed first, and only after them the navigation links. 假设您希望首先对字段进行标签,然后才对它们进行导航。 You can then write: 然后,您可以编写:

$('input').attr('tabindex', 1);
$('.nav a').attr('tabindex', 10000);

It's that simple in a simple case, since elements sharing the same tabindex value are tabbed in the order in which they appear in HTML source. 在一个简单的情况下就这么简单,因为共享相同tabindex值的元素按照在HTML源代码中出现的顺序进行标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM