Vue练习二十四:03_06_判断是否为两位数
Demo 在线地址:
https://sx00xs.github.io/test/24/index.html
---------------------------------------------------------------
ide: vscode
文件格式:.vue
解析:(待补)
<template>
<div id="app">
<input type="text" class="f-text" v-model="num" @keyup="handleNum">
<input type="button" value="是否为两位数" @click="handleClick">
</div>
</template>
<script>
export default {
data:function(){
return{
num:''
}
},
methods:{
handleClick(){
(this.num=='') ?
alert('请输入数字!') :
alert(/^\d{2}$/.test(parseInt(this.num)) ? '√ 是两位数' : "这是 "+this.num.length + ' 位数');
},
handleNum(){
this.num=this.num.replace(/[^\d]/,'')
}
}
}
</script>

浙公网安备 33010602011771号