所以我有一个非常简单的脚本,我正在编写一个计算器,这样客户就可以看到服务的成本,然后根据文本输入的更改更新结果。问题是在第一次绕过后它会停止正确计算值。在这里,帮助赞赏。
<script>
$(function(){
var one=0;
var two=0;
var three=0;
$("input:text").change(function(){
if($(this).val() == $('#first').val())
{
one = parseInt($(this).val());
}
else if($(this).val() == $('#second').val()){
two = parseInt($(this).val());
}
else if($(this).val() == $('#third').val()){
three = parseInt($(this).val());
}
});
$('input:text').change(function(){
$('#result').text(one+two+three);
});
});
</script>
和形式:
<div id="container">
<form action="something.html" id="subit">
<label for="first">put numbers</label><input type="text" id="first"/>
<label for="second">more numbers</label><input type="text" id="second" value="0"/>
<label for="third">and more numbers</label><input type="text" id="third" value="0"/>
<input type="submit" />
</form>
<div id="result"></>
</div>