所以我写了一个非常简单的脚本作为计算器,以便客户端可以看到服务将花费多少钱,然后根据对文本输入的更改更新结果。问题是在第一次出现后停止正确计算值。在这里,它是令人满意的。简单的计算器jquery脚本
<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>
您在第一次运行后更改'change()'函数,对吗? – Marc 2012-04-23 02:34:42
Marc,你是什么意思?基本上我首先要做的是:将值分配给变量,然后根据添加这些值更新结果。 – 2012-04-23 02:40:19
问题是“count”在第一轮添加后熄灭。添加val 1,2,3,然后尝试再次更改,结果是错误的。 – 2012-04-23 02:41:53