How to conduct arithmetic operations in JQuery?

前端 未结 5 1712
天命终不由人
天命终不由人 2021-01-03 14:04
var price     = $(\'#addprice\').val();
var pass      = $(\'#pass\').val();
var total     = $(\'#totalprice\').attr(\'value\')
var left      = $(\'#leftquota\').attr         


        
5条回答
  •  清酒与你
    2021-01-03 14:30

    Another option is to extend jQuery to be able to read numbers directly from form elements

    jQuery.fn.numVal = function() {
        return parseFloat(this.val()) || 0;
    }
    
       ....
    
      var price=$('#addprice').numVal();
      var pass=$('#pass').numVal()
    

提交回复
热议问题