有人帮我弄到了这段代码。
<input type="hidden" id="charge_total" value="charge_total">
还有这个 JavaScript
<script>
document.getElementById("charge_total").value = document.getElementById("system_cost").innerHTML;
我的问题是我使用的主机支付系统要求隐藏的输入有一个名字。
所以隐藏的输入一定是这样的
<input type="hidden" id="charge_total" name="charge_total" value="charge_total">
我的问题是使用代码时它没有在该字段中输入任何文本,我在结帐页面中留下了一个空白的总数。我需要这个 span ID 来输出它在这行代码中输入的隐藏值中的任何数字。
<p>Total: <span id="system_cost"> </span></p>
<input type="hidden" id="charge_total" name="charge_total" value="charge_total">
谁知道我做错了什么?
这是我将它放在页眉中的方式。
<script>
$(function(){ //on document ready attach handlers
$('form').on('submit', function(e){
e.preventDefault(); // stop the form submitting and do work
$('#charge_total').val(parseFloat($('#system_cost').text()));
$(this).submit(); //now submit the form, calculations are done
});
});
</script>
这是另外两行。
<input type="hidden" name="charge_total" value="charge_total">
<p>Total: <span id="system_cost"> </span></p>
跨度显示在页面上,就像它假设的那样并正确填充。只有隐藏值才显示 charge_total。
最佳答案
$(function(){ //on document ready attach handlers
$('form').on('submit', function(e){
e.preventDefault(); // stop the form submitting and do work
$('#charge_total').val(parseFloat($('#system_cost').text()));
this.submit; //now submit the form, calculations are done
});
});
关于javascript - 隐藏输入需要文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15592217/