• input只能输入数字小数点后两位


    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>

    </head>

    <body>
        <input style="-webkit-user-select:auto" type="Number" ref="Inp"
            onkeyup="this.value=this.value.replace(/[^d.]/g,'');" keyboardType="UIKeyboardTypeDecimalPad;" v-model="value"
            class="home-payment-input" @input="checkInput" autofocus @click="$refs.Inp.focus()" />



        <script>
            export default {
                data() {
                    return {
                        value: ""
                    }
                },
                methods: {
                    checkInput() {
                        this.value = this.dealInputVal(this.value);
                    },
                    dealInputVal(value) {
                        value = value.replace(/^0*(0.|[1-9])/, "$1");
                        value = value.replace(/[^d.]/g, ""); //清除"数字"和"."以外的字符
                        value = value.replace(/^./g, ""); //验证第一个字符是数字而不是字符
                        value = value.replace(/.{1,}/g, "."); //只保留第一个.清除多余的
                        value = value
                            .replace(".", "$#$")
                            .replace(/./g, "")
                            .replace("$#$", ".");
                        value = value.replace(/^(-)*(d*).(dd).*$/, "$1$2.$3"); //只能输入两个小数
                        value =
                            value.indexOf(".") > 0 ?
                            value.split(".")[0].substring(0, 10) + "." + value.split(".")[1] :
                            value.substring(0, 10);
                        if (value == "") {
                            this.disabled = true;
                        } else if (value == Number(0)) {
                            this.disabled = true;
                        } else if (value == "0.") {
                            this.disabled = true;
                        } else {
                            this.disabled = false;
                        }
                        return value;
                    },

                }
            }
        </script>
    </body>

    </html>
  • 相关阅读:
    Zookeeper实战
    Zookeeper的结构和命令
    Zookeeper中的选举机制
    du 命令,对文件和目录磁盘使用的空间的查看
    rm命令
    linux之cp/scp命令+scp命令详解
    android 为应用程序创建桌面快捷方式技巧分享
    对自己的文件使用keystore签名
    Android 打包签名 从生成keystore到完成签名 -- 转
    Android App启动错误的问题(connection to the server was unsuccessful)
  • 原文地址:https://www.cnblogs.com/1609359841qq/p/13272449.html
Copyright © 2020-2023  润新知