<div class="codetitle"> <span><a style="CURSOR: pointer" data="17460" class="copybut" id="copybut17460" onclick="doCopy('code17460')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code17460"> <br><br><br> <br> <meta charset="UTF-8"> <br> <title>Test</title> <br> <script type="text/javascript" src="jQuery/jquery-1.5.2.js"></script><br> <br> <script type="text/javascript"><BR> $(document).ready(function() {<BR> //敲击按键时触发<BR> $("#Score").bind("keypress", function(event) {<BR> var getValue = $(this).val();<BR> //控制第一个不能输入小数点"."<BR> if (getValue.length == 0 && event.which == 46) {<BR> event.preventDefault();<BR> return;<BR> }<BR> //控制只能输入一个小数点"."<BR> if (getValue.indexOf('.') != -1 && event.which == 46) {<BR> event.preventDefault();<BR> return;<BR> }<BR> //控制只能输入的值<BR> if (event.which && (event.which < 48 || event.which > 57) && event.which != 8 && event.which != 46) {<BR> event.preventDefault();<BR> return;<BR> }<BR> })<BR> //失去焦点是触发<BR> $("#Score").bind("blur", function(event) {<BR> var value = $(this).val(), reg = /\.$/;<BR> if (reg.test(value)) {<BR> value = value.replace(reg, "");<BR> $(this).val(value);<BR> }<BR> })<BR> });<BR> </script><br> <br> <input type="text" id="Score"><br> <br><br> </div>