Created
June 15, 2017 03:24
-
-
Save jiaosl/e580fbfe46016c03b19214c60f14b8b6 to your computer and use it in GitHub Desktop.
实时监测输入框内容变化,达到一定规则禁止输入(限制小数点前最多8位,小数点后最多4位)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title></title> | |
| </head> | |
| <body> | |
| <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> | |
| <input id="test"></input> | |
| <script> | |
| $('#test').bind('input propertychange', function() { | |
| let input = $('#test') | |
| let val = input.val() | |
| let splited = val.split('.') | |
| if(val.search(/\./) === -1){ | |
| input.val(val.slice(0,8)) | |
| }else{ | |
| input.val(splited[0].slice(0, 8)+'.' + splited[1].slice(0, 4)) | |
| } | |
| }) | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment