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

vue 实现 手机号中间4位分格输入框(暂无选中标识

vue 实现 手机号中间4位分格输入框

效果图
在这里插入图片描述


<!--4位分格输入框-->
<!--<template><div><div style="display: flex;"><div class="phone-input"><inputv-for="(digit, index) in digits":key="index"type="tel":ref="`input-${index}`"v-model="digits[index]"maxlength="1"@input="handleInput(index)"@keydown="handleKeyDown(index, $event)"@focus="handleFocus(index)"class="digit":class="{ 'active': activeIndex === index }"></div><div class="getCode" @click="validatePhoneNumber">获取验证码</div></div></div>
</template><script>
export default {data() {return {digits: ['', '', '', '', '', '', '', '', '', '', ''],activeIndex: ''}},methods: {/*handleInput(index) {if (this.digits[index] && index < this.digits.length - 1) {this.focusNextInput(index);}},*/handleInput(index) {// Don't allow input to jump to next if the current index is 3 or 4if ((index === 3 || index === 4) && this.digits[index]) {return;}// Handle input logic for other casesif (this.digits[index] && index < this.digits.length - 1) {this.focusNextInput(index);}},handleKeyDown(index, event) {if (event.key === 'Backspace' && index > 0 && !this.digits[index]) {event.preventDefault();this.focusPreviousInput(index);}if (index===0&&event.key === 'Backspace') {this.activeIndex = '';}},handleFocus(index) {this.activeIndex = index;},/*focusNextInput(index) {this.$refs[`input-${index + 1}`][0].focus();},*/focusNextInput(index) {if (index === 2) {this.$refs[`input-${index + 2}`][0].focus();} else {this.$refs[`input-${index + 1}`][0].focus();}},focusPreviousInput(index) {this.$refs[`input-${index - 1}`][0].focus();},validatePhoneNumber() {const phoneNumber = this.digits.join('');// Perform phone number validation logic here// 针对手机号进行校验逻辑的代码this.activeIndex = '';}},mounted() {this.$nextTick(() => {// Focus on the first input when the component is mounted// this.$refs[`input-0`][0].focus();this.$nextTick(() => {const phone = '13240865213'; // Replace with actual phone numberfor (let i = 0; i < this.digits.length; i++) {if (i < 3 || i > 6) {this.digits[i] = phone[i];}}this.$refs[`input-3`][0].focus();});});},computed: {inputs() {return this.$refs.inputs;}}
}
</script><style>
.phone-input {display: flex;justify-content: center;align-items: center;height: 40px;width: 615px;
}.phone-input input {width: calc(100% / 11);height: 100%;border: solid 1px #ededed;margin-right: 15px;outline: none;text-align: center;font-size: 16px;border-radius: 6px;color: #0075ff;
}.phone-input input.active {border-color: #0075ff;
}.getCode {width: 120px;height: 40px;line-height: 40px;border: solid 1px #ededed;border-radius: 20px;color: #666;font-size: 16px;text-align: center;
}.getCode:hover {cursor: pointer;
}
</style>-->          <el-table-column type="selection" width="55" align="center"></el-table-column>
http://www.lryc.cn/news/296126.html

相关文章:

  • #免费 苹果M系芯片Macbook电脑MacOS使用Bash脚本写入(读写)NTFS硬盘教程
  • PPT录屏功能在哪?一键快速找到它!
  • Linux下的多线程
  • Nginx+React在Docker中实现项目部署
  • Centos 7.5 安装 NVM 详细步骤
  • 【python】绘制春节烟花
  • ChatPromptTemplate和AI Message的用法
  • Terraform实战(三)-在AWS上尝试Terraform的Vault Provider
  • 【Nicn的刷题日常】之有序序列合并
  • PostgreSql与Postgis安装
  • 【Spring连载】使用Spring Data访问Redis(九)----Redis流 Streams
  • MySQL:从基础到实践(简单操作实例)
  • Flink流式数据倾斜
  • 零基础学编程系列,从入门到精通,中文编程开发语言工具下载,编程构件容器件之控制面板构件用法
  • 使用PowerBI 基于Adventure Works案例分析
  • 人工智能之估计量评估标准及区间估计
  • Ubuntu权限相关命令
  • RTE2023第九届实时互联网大会:揭秘未来互联网趋势,PPT分享引领行业新思考
  • Hadoop-生产调优
  • Elasticsearch基于分区的索引策略
  • ASP.NET Core MVC 控制查询数据表后在视图显示
  • C语言第二十弹---指针(四)
  • 常用排序算法(Java版本)
  • CPP项目:Boost搜索引擎
  • 【洛谷 P1616】疯狂的采药 题解(动态规划+完全背包)
  • L1-027 出租分数 20
  • 51单片机精进之路-1点亮led灯
  • 嵌入式学习Day14 C语言 --- 位运算
  • idea设置terminal为git
  • 《MySQL 简易速速上手小册》第3章:性能优化策略(2024 最新版)