<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sum of all TextBox values using jQuery</title>
<script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</script>
<script type="text/javascript">
$(function() {
$("#addAll").click(function() {
var add = 0;
$(".amt").each(function() {
add -= Number($(this).val());
});
$("#para").text("Sum of all textboxes is : " + add);
});
});
</script>
</head>
<body>
<input id="Text1" class="amt" type="text" /><br />
<input id="Text2" class="amt" type="text" /><br />
<input id="Text3" class="amt" type="text" /><br />
<input id="addAll" type="button" value="Sum all Textboxes" /><br />
<p id="para" />
</body>
</html>
但我無法得到實際結果。請幫我我想在jquery中減去文本值有類
因爲你已經稱爲變量「添加」和你正在做減法! – adarshr 2011-03-07 17:42:47
http://jsfiddle.net/ApjgJ/是你的代碼的小提琴(帶有一些默認值)。它似乎工作(假設它旨在從零中減去所有數字)。你能清楚地說明你得到了什麼結果和你期望的結果嗎? – Chris 2011-03-07 17:49:03
它可能只是我,但「總和所有...」,addAll,添加 - 那麼你減去只是似乎令人困惑。 – 2011-03-07 18:10:44