我希望有一个订单页面,允许客户选择一个项目及其数量,然后计算一个div中订购的总金额。
最初是我的代码:
对于数量jquery:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char* argv[]) {
int grid[9][9];
int input_error = 0;
int i, j;
if (argc != 1 + 9) { /* check number of rows in input */
input_error = 1;
} else {
for (i = 0; i < 9; i++) { /* read each rows */
if (strlen(argv[i + 1]) != 9) { /* check number of cols in input */
input_error = 1;
break;
}
for (j = 0; j < 9; j++) { /* read each cols */
if (isdigit(argv[i + 1][j]) && argv[i + 1][j] != '0') {
/* digits except for 0 */
grid[i][j] = argv[i + 1][j] - '0'; /* convert digit to integer */
} else if (argv[i + 1][j] == '.') {
/* dot */
grid[i][j] = 0;
} else {
/* invalid character */
input_error = 1;
break;
}
}
}
}
/* check if some errors are detected */
if (input_error) {
fputs("invalid usage\n", stderr);
return 1;
}
/* print what is read for testing */
for (i = 0; i < 9; i++) {
for(j = 0; j < 9; j++) {
printf(" %d", grid[i][j]);
}
putchar('\n');
}
return 0;
}
项目的HTML:
<script>
$(function() {
$(".numbers-row").append('<div class="inc button">+</div><div class="dec button">-</div>');
$(".button").on("click", function() {
var $button = $(this);
var oldValue = $button.parent().find("input").val();
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + "The Price";
} else {
// Don't allow decrementing below zero
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - "The Price";
} else {
newVal = 0;
}
}
$button.parent().find("input").val(newVal);
});
});
我的jquery总数:
<ul>
<li class="numbers-row">
<label>
<input class="calc" type="checkbox" name="combos[]" id="item2-title" value="The Name"/>
The Thumbnail<p>The Title</p>
<input type="hidden" name="item1-val" value="The Price">
</label>
</li>
<li class="numbers-row">
<label>
<input class="calc" type="checkbox" name="combos[]" id="item2-title" value="The Name"/>
The Thumbnail<p>The Title</p>
<input type="hidden" name="item2-val" value="The Price">
</label>
</li>
<li class="numbers-row">
<label>
<input class="calc" type="checkbox" name="combos[]" id="item2-title" value="The Name"/>
The Thumbnail<p>The Title</p>
<input type="hidden" name="item2-val" value="The Price">
</label>
</li>
</ul>
我的HTML将显示项目的总价格:
<script type="text/javascript">
function calcscore(){
var score = 0;
var checked=$(".calc:checked ~ input[type=hidden]").each(function(){
score+=parseInt($(this).val());
});
$('#price').text(score.toFixed(2));
}
$(document).ready(function(){
$(".calc").change(function(){
calcscore()
});
});
</script>
我似乎无法整合所有这些,任何帮助?
实际上有很多项目,但为了简化起见,我们会坚持使用3。
PS我只是基本的jquery和PHP但我可以复制粘贴到最少。任何输入都非常感谢。谢谢你们