Javascript 获取html标签文本,转换为数字,递增,然后使用结果更新标签文本

Javascript 获取html标签文本,转换为数字,递增,然后使用结果更新标签文本,javascript,html,label,increment,Javascript,Html,Label,Increment,我的网页上有一个标签 <label id="testLabelq" class="no_border" style="position: relative; top:-50px; margin: 0 auto; padding: 0px; width:20%; height: 25px;">1</label> 当我按下按钮时,标签的值不会改变 如果我换线 document.getElementById("testLabelq").innerHTML = "Test "

我的网页上有一个标签

<label id="testLabelq" class="no_border" style="position: relative; top:-50px; margin: 0 auto; padding: 0px; width:20%; height: 25px;">1</label>
当我按下按钮时,标签的值不会改变

如果我换线

document.getElementById("testLabelq").innerHTML = "Test " + quantity_int.toString();

然后,每次按下按钮时,标签文本都会更新为额外的“测试”

因此,我认为我的数字转换肯定有问题,但我不知道在哪里

谢谢,
Graham

函数中有语法错误(var
qantity\u int=
):


您的代码在稍微简化后似乎可以工作:

函数添加(){
var quantity_temp=document.getElementById(“testLabelq”).innerText;
变量数量=parseInt(数量温度,10)+1;
document.getElementById(“testLabelq”).innerHTML=quantity_int.toString();
}
1

+
哈哈,谢谢,我真不敢相信,我修正了打字错误,效果很好。
        function add()
    {
            var quantity_temp = document.getElementById("testLabelq").innerText; 

            var qantity_int = parseInt(quantity_temp, 10) + 1;

            document.getElementById("testLabelq").innerHTML = "Test " + quantity_int.toString();
    }
document.getElementById("testLabelq").innerHTML = "Test " + quantity_int.toString();
document.getElementById("testLabelq").innerHTML = "Test " + quantity_temp;
function add() {
    var quantity_temp = document.getElementById("testLabelq").innerText;
    var quantity_int = parseInt(quantity_temp, 10) + 1;
    document.getElementById("testLabelq").innerHTML = quantity_int.toString();
}