我已经用jeditable构建了一个包含自定义输入数字的表。一旦将值放入,输入类型就消失了
我需要找到一个JavaScript实时计算,自动使我的值的数量。
我发现有两个有趣的例子非常适合我的情况,但是有没有可能在不使用表单和输入的情况下实现同样的效果?
First example
Second example
发布于 2012-10-15 17:27:09
是的,是这样的。如您所知,document.getElementById('div_id')可以访问div元素,document.getElementById('div_id').value可以访问它的值。
因此,取出表单并为所需的div插入一个id,然后访问该值,然后找到和,然后将该值作为sum设置为另一个div。
<script>
function calculateBMI() {
var wtStr =document.getElementById('w').value;
if (!wtStr)
wtStr = '0';
var htStr = document.getElementById('h').value;
if (!htStr)
htStr = '0';
var weight = parseFloat(wtStr);
var height = parseFloat(htStr);
document.getElementById("r").value = weight + height;
}
</script>
<input id = "w" type="Text" name="weight" size="4" onkeyup="calculateBMI()"> Weight (in Kilos)
<input id = "h" type="Text" name="height" size="4" onkeyup="calculateBMI()"> Height (in Centimeters)<br>
<input id = "r" type="Text" name="BodyMassIndex" id="BodyMassIndex" size="4"> BMI
<input type="button" style="font-size: 8pt" value="Calculate" onClick="calculateBMI()" name="button">如果你不想要input,你可以使用textarea。
https://stackoverflow.com/questions/12892120
复制相似问题