如何获取span标记的值

dee*_*ell 8 html javascript jquery

如何获取span标记的值并将其发送到我的表单到另一个页面?

<span id="subtotal"></span>
Run Code Online (Sandbox Code Playgroud)

我需要将我的span标签小计的内容发送到另一个页面,我想将它保存到隐藏的字段中,但我发现没办法这样做..

我用过这个,但没有成功!

function getTotal() {
    return alert(document.getElementById('total').innerHTML);
}
Run Code Online (Sandbox Code Playgroud)

对于那些需要答案的人来说,这是正确的功能!在我弄清楚脚本之后......

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; 
}
Run Code Online (Sandbox Code Playgroud)

kob*_*obe 18

这会给你价值

$("#subtotal").text();
Run Code Online (Sandbox Code Playgroud)


Joh*_*ohn 7

.text()如果你正在使用jQuery,你可以试试这个方法.

$("#subtotal").text();
Run Code Online (Sandbox Code Playgroud)