vue.js 输入框金额限制
1、页面(有点丑):
2、代码:
<html>
<head>
<title>输入框</title>
<style>
div#table_id{
margin:10px;
}
.input{
padding:10px
}
</style>
</head>
<body>
<div id="table_id">
输入框的内容 <= 99 <br/>
<input class="input" type="text" v-model="info.use_fee" @input="changeNumFloat($event)">
</div>
</body>
<script src="https://cn.vuejs.org/js/vue.js"></script>
<script>
//let info = {:json_encode($info)};
let info = {'use_fee':99};
//let type_list = {:json_encode($type_list)};
let use_max_price = info.use_fee;
new Vue({
el: '#table_id',
data() {
return {
info: info,
//type_list: type_list
};
},
methods: {
changeNumFloat( e ) {
let newNum = e.target.value;
let oldNum = use_max_price;
if (isNaN(newNum)) {
this.info.use_fee = ''
}else{
if (parseFloat(newNum) < 0 || parseFloat(newNum) > parseFloat(oldNum)) {
this.info.use_fee = oldNum;
} else {
this.info.use_fee = newNum;
}
}
}
}
})
</script>
</html>
来源:CSDN
作者:一包伤心的辣条
链接:https://blog.csdn.net/qq_36025814/article/details/103481629