• 仅限正整数输入


    在某些浏览器不支持type number时这个是一个很好的替代方案

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
    2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3 <html xmlns="http://www.w3.org/1999/xhtml">
    4 <head>
    5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    6 <title>仅限正整数输入</title>
    7
    8 </head>
    9
    10 <body>
    11 <script>
    12 //void function (window,undefined){
    13 window.onload = function() {
    14 var doc = document,list = doc.getElementsByTagName('input');
    15
    16
    17 availableNumberInput(list);
    18 }
    19 function availableNumberInput(inputs) {
    20 var len = inputs.length,i,reg = /^(8|9|4[8-9]|5[0-7]|9[6-9]|10[0-5])$/ig;
    21
    22 document.onmousedown=function(){
    23 try{
    24 document.selection.empty()
    25 }catch(e){
    26 getSelection().removeAllRanges()
    27 }
    28 }
    29 for (i = len; i > 0; (inputs[--i].onkeydown = function(e) {
    30 e = window.event || e;
    31 var target = e.srcElement || e.target,code = e.charCode || e.keyCode;
    32 reg.lastIndex = 0;
    33 if (!reg.test(code) || e.shiftKey) {
    34 return false;
    35 }
    36 target.value === '0' && (target.value = '');
    37 },inputs[i].oncontextmenu = function() {
    38 return false;
    39 }),inputs[i].style.imeMode = 'disabled') {
    40 }
    41 }
    42 //}(window);
    43 </script>
    44
    45 拖个文字进输入框看看<br/>
    46 <input type="text"/><br/>
    47 <input type="text"/><br/>
    48 <input type="text"/>
    49 </body>
    50 </html>



  • 相关阅读:
    python第一个项目:爬取一个网站的所有图片
    python学习笔记(3)
    python学习笔记(3)
    python学习笔记(2)
    python学习笔记(2)
    机器学习入门(1)
    centos7安装google-chrome
    linux 系统监控命令之 top-(转自 Howie的专栏)
    linux 磁盘管理命令之df-(转自 Howie的专栏)
    sizeof()用法汇总-(转自风雷)
  • 原文地址:https://www.cnblogs.com/enix/p/2281663.html
Copyright © 2020-2023  润新知