2012-09-16 49 views
0

我正在使用这个到calculate total。这里是总脚本显示总计在jquery ajax没有点击文本字段

<!DOCTYPE HTML> 
<html lang="en-IN"> 
<head> 
    <meta charset="UTF-8"> 
    <title></title> 
    <script type="text/javascript" src="js/jquery1.7.2.js"></script> 
</head> 
<body> 
    <script type="text/javascript"> 
    jQuery(document).ready(function(){ 
     jQuery("#quantity, #unit_price, #tax").on('change',function(event){ 
     var subtotal = jQuery("#quantity").val() * jQuery("#unit_price").val(); 
     var total = subtotal + (subtotal * jQuery("#tax").val()/100); 
     jQuery("#total").val(total); 
     }); 
    }); 
    </script> 
    <table> 
    <tr> 
     <td> 
     <label for="unitcost">Unitcost</label> 
     <input type="text" id="unit_price" /> 
     </td> 
    </tr> 
    <tr> 
     <td> 
     <label for="quantity">Quantity</label> 
     <input type="text" id="quantity" /> 
     </td> 
    </tr> 
    <tr> 
     <td> 
     <label for="tax">Tax</label> 
     <input type="text" id="tax" /> 
     </td> 
    </tr> 
    <tr> 
     <td> 
     <label for="total">Total</label> 
     <input type="text" id="total" /> 
     </td> 
    </tr> 
    </table> 
</body> 
</html> 

但有一个问题。 Every time我得到click the text field才能得到result。我想要那个时候用户将enter the values in their fields it should show the total without click on input fields。我认为jquery ajax将在这里工作,但不知道如何在此实现。任何帮助和建议将是可观的。

回答

1

使用.keyup()它会显示没有点击输入字段总

jQuery("#quantity, #unit_price, #tax").keyup(function(event){ 

jQuery("#quantity, #unit_price, #tax").on('keyup',function(event){ 
+0

TEAD如何使用呢? – NewUser

+0

@新用户请检查现在我已经更新的答案 –

1

您可以尝试使用不同的事件点​​击,像KEYUP例如

尝试this fiddle

因此,的jQuery("#quantity, #unit_price, #tax").on('click',function(event){

使用jQuery("#quantity, #unit_price, #tax").on('keyup',function(event){