• 利用正则控制数字输入框


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>lik-input-number</title>
    </head>
    
    <body>
        <input type="text" class="lik_input_number" style="color:#ccc" value="请输入数字" onfocus="fn_focus(this);" onblur="fn_blur(this);" onkeydown="value = this.value.replace(/[^0-9.]/g, '');" onkeyup="value = this.value.replace(/[^0-9.]/g, '');">
    </body>
    
    <script src="jquery-1.8.1.min.js"></script>
    <script>
    
        // 输入框模拟placeholder
    
        function fn_focus(ele) {
            if (ele.value == ele.defaultValue) {
                ele.style = "color:#333";
                ele.value = '';
            } else {
                ele.style = "color:#333";
            }
        }
    
        function fn_blur(ele) {
            var reg = /^[s]*$/;
            if (reg.test(ele.value) || ele.value == ele.defaultValue) {
                ele.style = "color:#ccc";
                ele.value = ele.defaultValue;
            } else {
                ele.style = "color:#333";
            }
        }
    
    </script>
    </html>
    

      

    author:Lik
    Endeavoring to powerless, struggling to move yourself.
  • 相关阅读:
    15-数组concat()方法和push比较
    06-使用云储存上传工具
    05-云函数/云数据库的增删改查
    错题1
    c++链表
    8817
    8816
    1177
    1355
    c++期末考
  • 原文地址:https://www.cnblogs.com/likwin/p/7145331.html
Copyright © 2020-2023  润新知