如何将跨度值传递给laravel控制器 [英] how to pass span value into laravel controller

查看:48
本文介绍了如何将跨度值传递给laravel控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些售票程序,在该程序中,我可以自动计算票价.我将总价放入了< span> 标记中.我正在尝试将其放在< input> 标记上,以便将值传递到控制器会更容易,但是它不起作用.我已经在寻找解决方案,但是它永远不会结束.这是我的刀片的外观:

I am developing some ticket selling program, where I made an auto calculating ticket price. I put the total price into a <span> tag. I'm trying to put it on <input> tag so it will be easier to pass the value into controller, but it doesn't work. I've already searching for the solution but it never comes to end. This is what my blade looks like:

                  <table class="text-center  table-bordered" style="width:100%;">
                      <thead>
                          <tr>
                              <th>Quantity</th>
                              <th>Total</th>
                          </tr>
                      </thead>
                      <tbody>
                        <tr class="quantz">
                            <td class="product-quantity">
                                <input type="hidden" name="price[]" class="price" id="price" size="5px" readonly value="25000">
                                <input type="number" onchange="update();return false;" name="qty" value="1" min="1" id="quant" class="fl qty-text" >
                            </td>
                            <td class="product-total">
                                <span id="demo">IDR 25.000,-</span>
                            </td>
                        </tr>
                        <tr>
                          <td><h3><small>Your Cart Total - </small></h3></td>
                          <td><h3><input type="hidden" name="totalz" value=""><span id="sub_total">IDR 25.000,-</span></h3></td>
                        </tr>
                      </tbody>
                  </table>

这就是我在我的jquery中写的以获取值:

and this is what i wrote in my jquery to get the value:

<script>
    function update() {
    var total = 0;
    var fees = 0;
    var total_fees = 0;
    var tax_fix = 0;
    var with_fee = 0;
    var discount_amt = 0;
    var no_fee= 0;
    var tax= 0;
    $("#form-ui tr.quantz").each(function(i,o){
    if($(o).find("#quant").val()>=0){
      total += $(o).find("#quant").val() * $(o).find(".price").val();
      $(o).find("#demo").html(rupiah($(o).find("#quant").val() * $(o).find(".price").val()));
    }
    });
    console.log()
    fees  = (total*1);
    total_fees  = total+fees ;
    no_fee  = total;
    with_fee  = total + total_fees;

    //sub total
     $("#st").val(total);
     $("#sub_total").html(rupiah(total));

    //convinence_fee

    if(total == 0){
      fees = 0;
      total_fees = 0;
    }
      $("#fee").val(fees);
      $("#conv").html(rupiah(fees));
      //total_paid
      $("#total_price").val(total_fees);
      $("#total_paid").html(rupiah(total_fees));
      $("#hide_price").val(total_fees);

    }
    $("#form_payment tr.quantity").change(update);

    function rupiah(value){
    value += '';
    x = value.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
    return 'IDR ' + x1 + x2 + ",-";
    };
  </script>

有没有关于这个问题的解决方案?我应该在脚本或控制器中放些东西吗?

is there any solution regarding this problem? should I put something in my script or my controller?

推荐答案

jQuery可以与JQuery一起使用,它支持链接对象返回.

Possible with JQuery, jQuery supports chaining objects return.

在HTML中:

<span id="demo">IDR 25.000,-</span>
<input id="totalz" type="hidden" name="totalz" value="">

在JS中:

var data = $('#demo').html();
$('#total').val(data);

请确保您具有单个ID demo total ,如果您有多个具有相同属性的ID,那么它将与JavaScript冲突

Make sure that, you have single id demo, total, if you have multiple id with same attribute, then it will conflict with JavaScript

这篇关于如何将跨度值传递给laravel控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆