禁止input输入框显示历史记录(已解决)

67 篇文章 1 订阅
6 篇文章 0 订阅

需求

在这里插入图片描述

html的input 框获取光标后,会提示原来输入过的内容,还会出现下拉的历史记录
有时候项目中完全不需要这个,大家禁止这种情况基本都是在input中加入 autocomplete=“off”

<input type="text" autocomplete="off" />

还有一种办法就是更改ID,像下面这种,就不会有历史记录出现的

<input type="text" id="myinput" class="search-input" placeholder="在这里输入查询关键字" />

如果把ID改成像下面这个样子就会出现历史记录

<input type="text" id="keyword" class="search-input" placeholder="在这里输入查询关键字" />
<input type="text" id="keywords" class="search-input" placeholder="在这里输入查询关键字" />

id=“keyword” 会出现历史记录,id="keywords"会提示“在这里搜索”
也就是说,其实跟id的关键字有关系,如果input输入框没有设置id,就也不会弹出历史记录
如果设置了id,id不是keyword也不会出现,如果id非要设置了keyword那就加个autocomplete="off"禁止。

实现效果:
在这里插入图片描述

完整代码:

 <input  ref="codeBox"  v-model="barcode"  v-autofocus type="text" class="lightInput"
       :placeholder="条码编号"  @keyup.enter="toQuery"  @keydown.tab="toQuery"
 />
export default {
  name: "scanPacking",
  directives: {
    // 指令的定义
    autofocus: {
      inserted: function (el) {
        // 获得焦点
        el.focus();
      },
    },
  },
}

样式

<style>
.lightInput {
  border: none;
  width: 98%;
  text-indent: 5px;
  background: #2b2c2c !important;
  height: 30.5px;
  color: #ffffff;
}
.lightInput:focus {
  outline: 0;
  border: 1px solid rgb(0, 112, 70);
}
.lightInput::placeholder {
  color: #ffffff;
  font-size: 12px;
}
input::input-placeholder {
  color: #ffffff;
  font-size: 12px;
}
.lightInput::-webkit-input-placeholder {
  /* //兼容WebKit browsers(Chrome的内核) */
  color: #ffffff;
  font-size: 12px;
}
.lightInput::-moz-placeholder {
  /* //Mozilla Firefox 4 to 18 */
  color: #ffffff;
  font-size: 12px;
}
.lightInput::-moz-placeholder {
  /* //Mozilla Firefox 19+ */
  color: #ffffff;
  font-size: 12px;
}
.lightInput::-ms-input-placeholder {
  /* //Internet Explorer 10+ */
  color: #ffffff;
  font-size: 12px;
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值