当前位置: 首页 > news >正文

肇庆网站开发公司编程培训机构加盟哪家好

肇庆网站开发公司,编程培训机构加盟哪家好,漯河 做网站,丰都网站建设案例先看下效果如下&#xff1a; 动态图如下 uniapp的keyup获取不到keyCode和compositionstart&#xff0c;compositionend&#xff0c;所以需要监听input节点的keyup事件&#xff0c; 思路以及代码如下&#xff1a; 1.将每一个字符用文本框输入&#xff0c;代码如下 <view …

先看下效果如下:
在这里插入图片描述
动态图如下
在这里插入图片描述
uniapp的keyup获取不到keyCode和compositionstart,compositionend,所以需要监听input节点的keyup事件,

思路以及代码如下:
1.将每一个字符用文本框输入,代码如下

<view class="license-input"><input type="text" class="input-code code0" /><input type="text" class="input-code code1" />...
</view>

2.初始化的时候将input下的真是inputdom绑定keyup事件调用skipnext,并传入每一个input的index,同时绑定compositionstart和compositionend

mounted(){document.querySelectorAll(".input-code").forEach((el, index) => {const input = el.querySelector("input");if (index > 0) {input.disabled = true;}input.addEventListener("keyup", (event) => {this.skipnext(index, event);});input.addEventListener("compositionstart", this.inputstart);input.addEventListener("compositionend", this.inputend);});
}

3.对按键进行处理,如果当前文本框已经输入完成则跳转到下一个文本框,如果没有则停留在当前文本框,第一次输入的时候,前面的没有输入完成,则不可跳过前面的号码去输入后面的号码,当删除后则解除禁止

完整代码如下:
新建license-input.vue文件,

<template><view class="license-input"><input type="text" class="input-code code0" /><input type="text" class="input-code code1" /><span class="dian">·</span><input type="tel" class="input-code code2" /><input type="tel" class="input-code code3" /><input type="tel" class="input-code code4" /><input type="tel" class="input-code code5" /><input type="tel" class="input-code code6" /></view>
</template><script>
/***  车牌照输入* ===== 使用场景 ======* 下单页面ETC**/
export default {name: "license-input",props: {carvalue: {type: String,default: "",},},mounted() {this.setEvent();},methods: {setEvent() {const v = this.carvalue.split("");document.querySelectorAll(".input-code").forEach((el, index) => {const input = el.querySelector("input");input.value = v[index] || "";if (index > 0) {input.disabled = true;}input.addEventListener("keyup", (event) => {this.skipnext(index, event);});input.addEventListener("compositionstart", this.inputstart);input.addEventListener("compositionend", this.inputend);});this.$emit("input", this.carvalue);},getVal() {let val = "";document.querySelectorAll(".input-code").forEach((el, index) => {val += el.querySelector("input").value;});return val;},skipnext(num, e) {const keycode = e.keyCode || e.which;if (e.target.timer) {clearTimeout(e.target.timer);e.target.timer = null;}// tab,ctrl,回车,Enter等可自定排除if (keycode == 9 || keycode == 13 || keycode == 18 || keycode == 32) {return;}//删除按键if (keycode == 8) {if (num > 0 && !e.target.value) {const prevel = document.querySelector(`.code${num - 1}`).querySelector("input");//   e.target.disabled = true; // 删除后将disabled 设置为trueprevel.focus();}this.$emit("input", this.getVal());return;}if (num < 6 && !e.target.hascom) {const nextel = document.querySelector(`.code${num + 1}`).querySelector("input");// 添加延迟,防止过快输入。e.target.timer = setTimeout(() => {nextel.disabled = false;nextel.focus();}, 300);}// 只能输入一个字符if (e.target.value.length > 1 && !e.target.hascom) {e.target.value = e.target.value.substr(e.target.value.length-1, 1);}this.$emit("input", this.getVal());},inputstart(e) {e.target.hascom = true;},inputend(e) {e.target.hascom = false;},},
};
</script>
<style>...</style>

父组件使用

<license-input carvalue="浙A12345" @input="(e) => {carmodel = e}"></license-input>车牌为:{{carmodel }}import licenseInput from "@/components/license-input.vue";
http://www.mmbaike.com/news/78946.html

相关文章:

  • 呼和浩特市做网站公司好的广州线上教学
  • 有服务器域名源码怎么做网站平台品牌策划包括哪几个方面
  • 专门做英雄联盟h漫的外国网站seo搜索引擎优化论文
  • seo网站推广如何做站长之家seo查找
  • 日本 男女做受视频网站营业推广的方式
  • 宜州做网站需要多少钱市场营销策划案的范文
  • 新疆建设教育协会网站论坛软文案例
  • 建设工程质量检测管理办法沈阳网站关键词优化多少钱
  • 商城网站网络公司seo技术助理
  • 网站设计首页山东做网站公司
  • 自己做的网站如何兼容ie11谷歌优化
  • 如何用wordpress建一个网站分析影响网站排名的因素
  • 美女做暖暖的视频网站中国最新领导班子
  • 社保汇算清缴哪个网站做的网店产品seo如何优化
  • 重庆专门做网站的公司整合营销传播策略
  • 株洲营销型网站建设seo网站结构优化
  • 怎么搭建网站友情链接网络营销策划怎么写
  • 做网站公司 上海八百客crm登录入口
  • 天助网的网站seo诊断报告怎么写
  • 怎么做asp网站推广代理平台登录
  • 关于旅游网站策划书核心关键词
  • 广东建设企业网站哪家好软文营销网
  • 便宜建站vps站长网站工具
  • 静态网站怎么做百度营销登录平台
  • 太原定制网站制作流程搜狗竞价推广效果怎么样
  • 网站开发antnwgoogle优化推广
  • pdf 网站建设搜狗站长
  • 加强政府网站建设工作电脑优化大师哪个好
  • 网站刷新新前台是什么意思论坛推广工具
  • 网络服务提供者知道或应当知道seo排名优化软件免费