繁体   English   中英

如何将Span Id值转换为PHP变量?

[英]How to get Span Id value into PHP Variable?

我有点困惑如何将跨度ID值转换为PHP变量。 当我尝试DOM时,Span变成将无法工作。 我想存储Span ID“ sum”的值。 请帮助我。

HTMl + PHP形式:

<div class="form-sep">
  <div class="row-fluid">
    <div class="span6">
      <label class="field-title">Fees Particular [A] + [B] = [Payble Fees]</label>
      <input type="text" name="valuesum" class="valuesum" value="<?php $mf = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM total_fees where class = '$qry[class]'")); $m_f = $mf['total_fees']/10; echo $m_f;?>" > +
      <input type="text" name="valuesum" class="valuesum" value="<?php echo $i; ?>" > =
      <td align="center"><strong>Rs. <span id="sum"></span></strong></td>
    </div>
  </div>
</div>

脚本:

<script>
    $(document).ready(function(){

        //iterate through each textboxes and add keyup
        //handler to trigger sum event
        $(".valuesum").each(function() {

            $(this).keyup(function(){
                calculateSum();
            });
        });

    });

    function calculateSum() {

        var sum = 0;
        //iterate through each textboxes and add the values
        $(".valuesum").each(function() {

            //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum += parseFloat(this.value);
            }

        });
        //.toFixed() method will roundoff the final sum to 2 decimal places
        $("#sum").html(sum.toFixed(2));
    }
</script>

您在HTML中遇到问题,jQuery正常工作。

更新小提琴

<div class="form-sep">
    <div class="row-fluid">
        <div class="span6">
            <label class="field-title">Fees Particular [A] + [B] = [Payble Fees]</label>
            <input type="text" name="valuesum" class="valuesum" value="<?php $mf = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM total_fees where class = '$qry[class]'")); $m_f = $mf['total_fees']/10; echo $m_f;?>" > +
            <input type="text" name="valuesum" class="valuesum" value="<?php echo $i; ?>" > =
            <td align="center"><strong>Rs. <span id="sum"></span></strong></td>
        </div>
    </div>
</div>

您不能在input运行mysql查询,正确的方法是,首先运行查询

<?php $mf = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM total_fees where class = '$qry[class]'"));
$m_f = $mf['total_fees']/10;
?>

然后在input中将变量放入value

<input type="text" name="valuesum" class="valuesum" value="<?php echo $m_f;?>" >

要存储值,首先必须将其存储到输入中(检查更新的小提琴)

<input type="text" name="total" id="total" value="" >

然后以表格形式发布并存储到数据库中,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM