我正在尝试创建一种 pc builder 但是在使用下拉列表时,它不会更新价格;
$(document).ready(function()
{
var total = 0; //Base price
function calcTotal()
{
$("select").each(function()
{
//This happens for each checked input field
var cost = $(this).val(); //I beleive the problems are here and...
total += parseInt(cost); //total = total + cost
});
}
//This happens when the page loads
calcTotal();
$("form").before('<p class="total">Base Price of Your Custom PC: <strong>£' + total + '</strong></p>');
$(":submit").before('<p class="total">Base Price of Your Custom PC: <strong>£' + total + '</strong></p>');
$("input:checkbox, input:radio").click(function() //... and problem here?
{
total = 0; //Base price
calcTotal();
$("p.total").html("Total Cost of Your Custom PC: <strong>£" + total + "</strong>");
});
});
还有我的html;
<head>
<title>Test - PC Builder</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">google.load("jquery", "1")</script>
<script src="t.js" type="text/javascript"></script>
</head>
<body>
<form action="###" method="post">
Choose an Operating System
<input type="hidden" value="1" name="qty1">
<select name="productpr1">
<option value="Case A:10">---</option>
<option cost="25" value="Win 7:25">Win 7 (add £25)</option>
<option cost="50" value="Win 8:50">Win 8 (add £50)</option>
</select>
<br>
Choose a Case
<input type="hidden" value="1" name="qty2">
<select name="productpr2">
<option value="Case A:10">---</option>
<option cost="10" value="Case A:10">Case A (add £10)</option>
<option cost="15" value="Case B:15">Case B (add £15)</option>
</select>
<!-- Send Button -->
<input name="return" type="hidden" value="#">
<input type="submit" value="Buy Now!">
</form>
</body>
</html>
我将cost=""
其用作计算计算的值,但是当我加载 html 页面时,我得到£NaN
了价格的值?我不能使用 value 属性,因为它用于另一个功能。
任何人都可以帮忙吗?