所以我寫了一個非常簡單的腳本作爲計算器,以便客戶端可以看到服務將花費多少錢,然後根據對文本輸入的更改更新結果。問題是在第一次出現後停止正確計算值。在這裏,它是令人滿意的。簡單的計算器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