【问题标题】:Jquery get value using class nameJquery使用类名获取值
【发布时间】:2014-07-07 03:15:51
【问题描述】:

我正在尝试获取输入文本字段(价格)的值并将其乘以数量,然后进行一些扣除并显示在总列上。((price * quantity) - credit)

这里是jsfiddle

我怎样才能得到上面小提琴中的每个数量值?

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    你需要找到当前.totalclosesttr,然后在其中找到.quantity元素

        $('.total').text(function () {
            var q = $(this).closest('tr').find('.quantity').text()
            var credit = $(this).prev().text();
            q = q.replace(/,/g, '');
            p = p.replace(/,/g, '');
            credit = credit.replace(/,/g, '');                
    
            tot = ((parseFloat(p) * parseFloat(q)) - (parseFloat(credit)));
            tot = Math.floor(tot*100)/100;
            return tot.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        });
    

    演示:Fiddle

    【讨论】:

      猜你喜欢
      • 2011-01-24
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2019-09-30
      相关资源
      最近更新 更多