找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 48|回复: 1

[建议] 建议tab或别的键能在文本框之间跳动。

[复制链接]

27

主题

152

回帖

897

积分

高级会员

积分
897
发表于 昨天 17:21 | 显示全部楼层 |阅读模式
  用快捷键进入网页上的第一个文本框后,再用Tab或其他快捷键,可以在网页上的文本框之间跳转。
  现在则是进入第一个文本框后,再按Tab,焦点就落在了一些不可预测的链接上了。

回复

使用道具 举报

12

主题

1万

回帖

2万

积分

超级版主

(^^ゞ

积分
29150
发表于 昨天 20:23 | 显示全部楼层
本帖最后由 S8F8ry 于 2026-11-5 20:24 编辑

这个其实应该是网页的开发者设计和考虑的。或者你可以试试使用下面这个油猴脚本:
  1. // ==UserScript==
  2. // @name         文本框 Tab 切换
  3. // @version      0.1.0
  4. // @description  使用 Tab / Shift+Tab 在文本框之间跳转,跳过链接和按钮
  5. // @author       dragonish
  6. // @namespace    https://github.com/dragonish
  7. // @license      GNU General Public License v3.0 or later
  8. // @match        *://*/*
  9. // @grant        none
  10. // @run-at       document-idle
  11. // ==/UserScript==

  12. (function () {
  13.   const EXCLUDE_TYPES = new Set(["hidden", "checkbox", "radio", "button", "submit", "reset", "file", "range", "color", "image"]);
  14.   function isTextbox(el) {
  15.     if (!el || !(el instanceof HTMLElement)) return false;
  16.     if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
  17.       if (el.disabled) return false;
  18.     }
  19.     if (el.isContentEditable) return true;
  20.     if (el instanceof HTMLTextAreaElement) return true;
  21.     if (el instanceof HTMLInputElement) {
  22.       return !EXCLUDE_TYPES.has((el.type || "text").toLowerCase());
  23.     }
  24.     return false;
  25.   }
  26.   function isVisible(el) {
  27.     if (el.getClientRects().length === 0) return false;
  28.     const cs = getComputedStyle(el);
  29.     return cs.display !== "none" && cs.visibility !== "hidden";
  30.   }
  31.   function getTextboxes() {
  32.     return Array.from(document.querySelectorAll('input, textarea, [contenteditable="true"]')).filter(el => isTextbox(el) && isVisible(el));
  33.   }
  34.   document.addEventListener("keydown", e => {
  35.     if (e.key !== "Tab" || e.ctrlKey || e.metaKey || e.altKey) return;
  36.     const active = document.activeElement;
  37.     if (!isTextbox(active)) return;
  38.     e.preventDefault();
  39.     e.stopPropagation();
  40.     const boxes = getTextboxes();
  41.     const idx = boxes.indexOf(active);
  42.     if (idx === -1) return;
  43.     const next = e.shiftKey ? (idx - 1 + boxes.length) % boxes.length : (idx + 1) % boxes.length;
  44.     boxes[next]?.focus();
  45.   }, true);
  46. })();
复制代码


¯\(°_o)/¯
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|百分浏览器论坛

GMT+8, 2026-11-6 02:04 , Processed in 0.009157 second(s), 4 queries , Redis On.

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表