我尝试打印选中复选框的总值。
它已经适用于 input type="checkbox">
但它已经用 asp:checkbox/> 编写了代码。
我试过了,但打印出来的是 NaN。
代码如下: 四个复选框
<asp:CheckBox runat="server" ID="CheckBox1" Text="Mobile" Value="70" onclick="checkcount(this);" />
<asp:Label ID="lbltotal" runat="server" ClientIDMode="Static"></asp:Label>
int amount=0;
function checkcount(item)
{
amount += parseInt(document.getElementById(item.id).value);
alert(amount);
document.getElementById("lbltotal").innerHTML = amount;
}
最佳答案
parseInt(document.getElementById(item.id));
应该是:
parseInt(document.getElementById(item.id).value);
关于javascript - 如何在具有总值的复选框上应用 javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12318633/