[英]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.