V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Adicwu
V2EX  ›  React

mac 系统中, input 在输入中文时按回车,会触发 enter 事件,如何隔离这种行为(像 windows 一样)

  •  
  •   Adicwu · Mar 4, 2024 · 1604 views
    This topic created in 794 days ago, the information mentioned may be changed or developed.
    Adicwu
        1
    Adicwu  
    OP
       Mar 4, 2024
    已解决
    LinYaXuan
        2
    LinYaXuan  
       Mar 4, 2024
    https://greasyfork.org/zh-CN/scripts/470612-chagpt-safari-中文输入法回车键修复/code
    参考这个扩展一下匹配网站应该能解决 web 上的问题。
    代码很短
    ```js
    document.addEventListener(
    "keydown",
    (e) => {
    if (e.keyCode == 229) e.stopPropagation();
    },
    true
    );

    ```
    Adicwu
        3
    Adicwu  
    OP
       Mar 5, 2024
    @LinYaXuan keyCode 已弃用;最后用 compositionstart/compositionend 配合 keydown 实现的
    devzhaoyou
        4
    devzhaoyou  
       Mar 22, 2024
    这个问题 gpt 不很容易答出来么
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   994 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:47 · PVG 02:47 · LAX 11:47 · JFK 14:47
    ♥ Do have faith in what you're doing.