daihu
<input style="margin-top: 10px;width: 100%;text-align:center;" id="removeArea"
                                               value="0" onclick="showIllegalBuildingsDetail(\'removeArea\')"
                                               onkeyup="onlyNumber(this)"
                                               onblur="onlyNumber(this)">



// input输入限制,只允许输入数字和“.”,长度不得超过20
    function onlyNumber(obj) {
        //先把非数字的都替换掉,除了数字和.
        obj.value = obj.value.replace(/[^\d\.]/g, \'\');
        //必须保证第一个为数字而不是.
        obj.value = obj.value.replace(/^\./g, \'\');
        //保证只有出现一个.而没有多个.
        obj.value = obj.value.replace(/\.{2,}/g, \'\');
        //保证.只出现一次,而不能出现两次以上
        obj.value = obj.value.replace(\'.\', \'$#$\').replace(/\./g, \'\').replace(\'$#$\', \'.\');
        obj.value = obj.value.substring(0, 20);
    }

 

分类:

技术点:

相关文章: