sayitagain
V2EX  ›  问与答

vue+element input 被 chrome 认为是用户名输入框

  •  
  •   sayitagain · May 27, 2020 · 1944 views
    This topic created in 2184 days ago, the information mentioned may be changed or developed.

    最近前端这边遇到了一个问题,项目是 vue+element 写的,但是只要页面有 input 元素,那么页面的最后一个 input 都会出现浏览器认为这是个用户名输入框,点击会出现用户名密码选择,有些版本的 chrome 甚至还自动填充了第一个用户名.百度了下好像没有什么较好的方法,看的最多的就是多写一个隐藏的 input 来欺骗浏览器.

    有没有大佬遇到过,是否可以通过 element 组件上的属性设置来规避?

    比如下图的搜索框,浏览器也认为是用户名输入框...

    input 渲染后的 html <input type="text" autocomplete="off" placeholder="搜索课程" class="el-input__inner">

    7 replies    2020-05-27 16:30:31 +08:00
    sayitagain
        1
    sayitagain  
    OP
       May 27, 2020
    额!我似乎还没权限发图片网址...
    ss098
        2
    ss098  
       May 27, 2020
    autocomplete 属性。
    ChanKc
        3
    ChanKc  
       May 27, 2020 via Android
    有可能是页面上这个 input 后面还有个 input 是密码输入
    ChanKc
        4
    ChanKc  
       May 27, 2020 via Android
    做了个简单的测试,把一个 input password 放在紧跟在 input text 后面的隐藏的 div 里面(通常是个模态框),就会有这个情况
    ChanKc
        5
    ChanKc  
       May 27, 2020 via Android
    解决办法也很简单,用<form>代替你的<div>,用 form 严格区分不同的表单
    sayitagain
        6
    sayitagain  
    OP
       May 27, 2020
    @ChanKc form 我一会让前端试试看
    sayitagain
        7
    sayitagain  
    OP
       May 27, 2020
    @ss098 chrome 是不会管这个属性的.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1474 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:01 · PVG 01:01 · LAX 10:01 · JFK 13:01
    ♥ Do have faith in what you're doing.