请教各位大牛,是这样的,我想在jsp页面上实现这样一个功能:
网页里面有一个表格,总共有三个单元格,第一个是单价,第二个是数量,第三个是总价,能否实现这样的一个功能,我在网页上输入单价跟数量之后,第三个单元格直接就输出总价???
最好给出代码jsp 网页 表格
网页里面有一个表格,总共有三个单元格,第一个是单价,第二个是数量,第三个是总价,能否实现这样的一个功能,我在网页上输入单价跟数量之后,第三个单元格直接就输出总价???
最好给出代码jsp 网页 表格
<tr>
<td>单价</td>
<td>数量</td>
<td>总价</td>
</tr>
<tr>
<td><input type="text" id="price" onblur="getTotalPrice()"/></td>
<td><input type="text" id="num" onblur="getTotalPrice()"/></td>
<td id="totalPrice"></td>
</tr>
</table>
</body>
<script type="text/javascript" >function getTotalPrice(){ var price = document.getElementById("price").value;
var num = document.getElementById("num").value;
if(price !='' && num !=''){
document.getElementById("totalPrice").innerHTML = (price*num).toFixed(2);
}
}
</script>
<table>
<tr>
<td>单价</td>
<td>数量</td>
<td>总价</td>
</tr>
<tr>
<td><input name="singPrice" onblur="calc()" id="singPrice"/></td>
<td><input name="count" onblur="calc()" id="count"/></</td>
<td><input name="totalPrice" id="totalPrice"/></</td>
</tr>
//js代码
function calc() {
var singPrice = document.getElementById("singPrice").value;
var count = document.getElementById("count").value;
//判断value
if (isNaN(singPrice)) {
document.getElementById("singPrice").value = "";
return false;
}
if (isNaN(count)) {
document.getElementById("count").value = "";
return false;
}
var totalPrice = singPrice * count;
document.getElementById("totalPrice ").value = totalPrice ;
}</table>