我正在使用 jsp、mysql、ajax 使用 netbeans 和 mysql 做一个网络项目。 我有 3 个文本框,其中 2 个用于获取用户的输入。第三个文本框应显示 2 个输入值的乘积。
如何做到这一点? 我应该进行 ajax 调用还是可以在 3 文本框中调用 java 函数。
代码是
<input type="text" value="" name="quantity"/>
</td><td><input type="text" value="" name="price"/>
</td><td><input type="text" value="" name="total"/>
在名为“total”的文本框的值属性中,我可以调用 java 函数吗?
类似于 value="getTotal()"
,但如果我可以的话,我该如何访问其他两个值。
否则我应该进行 ajax 调用吗?
最佳答案
嗨, friend ,不需要去 java 函数......你可以做简单的客户端
<td><input type="text" value="" name="quantity" onblur="Calculate()"/>
</td><td><input type="text" value="" name="price" onblur="Calculate()"/>
</td><td><input type="text" value="" name="total"/>
<script type="text/javascript">
function Calculate()
{
var txt1 = document.getElementById("quantity");
var txt2 = document.getElementById("price");
var txt3 = document.getElementById("total");
if ((txt1.value != "") && (txt2.value != ""))
{
txt3.value = parseInt(txt1.value) * parseInt(txt2.value);
}
}
</script>
嗨, friend ,还有一件事总文本框应该是只读的,或者你可以使用标签....
谢谢
关于javascript - 我们可以从 html 文本框中调用 java 函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515860/