简体   繁体   English

如何禁用对特定 html 元素的关注?

[英]How to disable focus on specific html elements?

I have custom input component in vue js , and in this component i have input and two buttons.when input loose focus, i want to focus on next input, but now it focus on those buttons.我在vue js有自定义输入组件,在这个组件中我有输入和两个按钮。当输入松散焦点时,我想专注于下一个输入,但现在它专注于那些按钮。 finally i should press tab key three times to focus on next input.最后我应该按三下 tab 键来专注于下一个输入。

Is there any html attribute for disabling focus on some elements?是否有任何 html 属性可以禁用对某些元素的关注? or there is a javascript way?或者有一种javascript方式?

The tabindex attribute controls tabbing. tabindex 属性控制制表符。 Set it to -1 and the tab key will not stop on that element.将其设置为 -1 并且 Tab 键不会在该元素上停止。

<button tabindex="-1">click me</button>

You could use the blur event which is an equivalent of https://www.w3schools.com/jsref/event_onfocusout.asp <input v-on:blur="handleBlur">您可以使用 blur 事件,它相当于https://www.w3schools.com/jsref/event_onfocusout.asp <input v-on:blur="handleBlur">

To trigger something when you lose focus.当你失去焦点时触发某事。

You also could create a tabindex tabindex="0" on elements to determine the order of tabbing.您还可以在元素上创建 tabindex tabindex="0"来确定 Tab 的顺序。

Unfortunately you can't make an element non focus-able unless you want to disable the whole element.不幸的是,除非您想禁用整个元素,否则您无法使元素不可聚焦。 Because then you couldn't type anything into that input.因为那样你就无法在该输入中输入任何内容。

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

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