Jquery选择器,控制输入数字,并自动求值

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
    <script type='text/javascript' src='jquery-1.4.2.js'> </script>
 </head>
  <script type="text/javascript">  
     $.fn.numeral = function () {   //注册一个全局函数numeral  
         $(this).css("ime-mode", "disabled");  
         this.bind("keypress", function () {  
             if (event.keyCode == 46) {  
                 if (this.value.indexOf(".") != -1) {  
                     return false;  
                 }  
             } else {  
                 return event.keyCode >= 46 && event.keyCode <= 57;  
             }  
         });  
         this.bind("blur", function () {  
             if (this.value.lastIndexOf(".") == (this.value.length - 1)) {  
                 this.value = this.value.substr(0, this.value.length - 1);  
             } else if (isNaN(this.value)) {  
                 this.value = "";  
             }  
         });  
         this.bind("paste", function () {  
             var s = clipboardData.getData('text');  
             if (!/\D/.test(s));  
             value = s.replace(/^0*/, '');  
             return false;  
         });  
         this.bind("dragenter", function () {  
             return false;  
         });  
         this.bind("keyup", function () {  
             if (/(^0+)/.test(this.value)) {  
                 this.value = this.value.replace(/^0*/, '');  
             }  
         });  
     };  
 </script>  

 <script type="text/javascript" language="javascript">  
     $(function () {  
         OnlyInPutNumber();  
     });  
  
     function OnlyInPutNumber() {  
         $("input[id^='a']").numeral(); //找到id以dgItem_txt开头的一组文本框  
     }  
 </script>

 <body>
  

单价:<input name="a" type="text" id="a" onBlur="c.value=a.value*b.value"><br>
数量:<input name="b" type="text" id="b" value="3"  disabled><br>
总金额:<input name="c" type="text" id="c" disabled>
 </body>

</html>

 

你可能感兴趣的:(jquery选择器)