gpt4 book ai didi

javascript - 如何将 Span Id 值放入 PHP 变量中?

转载 作者:行者123 更新时间:2023-12-03 09:23:09 25 4
gpt4 key购买 nike

我有点困惑如何将 Span 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 工作正常。

Updated Fiddle

<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;?>" >

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

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

然后用表单发布并存储到数据库中,

关于javascript - 如何将 Span Id 值放入 PHP 变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31776593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com