[英]How can i get the values of product tags created using javascript in span and pass the values to controller?
[英]How Do I get the values of span tags
如何获取 span 标记的值并将其发送到我的表单中到另一个页面?
<span id="subtotal"></span>
我需要将我的 span 标签小计的内容发送到另一个页面,我想将它保存到一个隐藏字段中,但我发现没有办法做到这一点..
我用过这个,但没有成功!
function getTotal() {
return alert(document.getElementById('total').innerHTML);
}
对于那些需要答案的人来说,这是正确的功能! 在我弄清楚剧本之后......
function getTotal() {
//document.write(document.getElementById('total').innerHTML);
var someValue = $(".total").text();
alert("Value is "+someValue);
//It cause to releoad the page and give me the parameter total
location.href="frmAdd.php?total=" + someValue;
}
这会给你价值
$("#subtotal").text();
如果您使用 jQuery,您可以尝试.text()
方法。
$("#subtotal").text();
span 的值添加到 id="sub" 的输入字段中。 您可以使用任何事件为隐藏字段分配值,例如单击、更改、提交,或者您按照逻辑进行操作。这是一个选项。
$("#sub").val($("#subtotal").text());
<span id="subtotal"></span>
<input type="hidden" id="sub" >
你不应该在那里有subtotal
而不是total
吗?
function getTotal() {
return alert(document.getElementById('subtotal').innerHTML);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.