日期:2014-05-17  浏览次数:20653 次

如何根据表单中的值进行计算
如何根据jsp中的下拉框中的选择的值,还有其他输入框的值,去计算在jsp中另外一个输入框的值,
亲们,这是怎么做的啊
------解决方案--------------------
方法1:用定时器,定时去获取下拉框和输入框的值 计算出来然后给计算输入框赋值
方法2:监听下拉框和输入框的事件(比如onchange之类的),事件触发后去获取下拉框和输入框的值 然后计算赋值
------解决方案--------------------

<script type="text/javascript">
function countIt(){
    var select = document.getElementById("selectid").value;
    var input = document.getElementById("inputid").value;
    document.getElementById("otherid").value = Number(select)*Number(input);
}
</script>
<select id='selectid' onchange='countIt()'>
<option></option>
<option></option>
<option></option>
<option></option>
</select>
<input type='text' id='inputid' onkeyup='countIt()'/>
<input type='text' id='otherid' readonly/>

------解决方案--------------------
jquery
相加或许简单点,再有其他运算的麻烦点