[英]Error Uncaught Error: Syntax error, unrecognized expression
<div class="mt-repeater-item">
<div class="row mt-repeater-row">
<input type="text" name="product[0][price]" value="2" oninput="update_total(this)">
</div>
</div>
<div class="mt-repeater-item">
<div class="row mt-repeater-row">
<input type="text" name="product[1][price]" value="3" oninput="update_total(this)">
</div>
</div>
And my script 还有我的剧本
function update_total(input) {
var sum = 0;
$('.mt-repeater-item').each(function(index) {
var product_price = $("input[name=product["+index+"][price]]").val() ? $("input[name=product["+index+"][price]]").val() : 0;
sum = sum + product_price;
});
alert(sum);
}
Error Uncaught Error: Syntax error, unrecognized expression
=> How to fix it? Error Uncaught Error: Syntax error, unrecognized expression
=>如何解决?
function update_total(input) {
var sum = 0;
$('.mt-repeater-item').each(function(index) {
var product_price = $("input[name='product["+index+"][price]']").val() ? $("input[name='product["+index+"][price]']").val() : 0;
sum = sum + parseInt(product_price);
});
alert(sum);
}
enclose value of name
inside single quotes 将
name
值括在单引号中
You have missing quotation for name -- 您的姓名缺少引号-
function update_total(input) {
var sum = 0;
$('.mt-repeater-item').each(function(index) {
var product_price = $("input[name='product["+index+"][price]']").val() ? $("input[name='product["+index+"][price]']").val() : 0;
sum = sum + product_price;
});
alert(sum);
}
Link - https://jsfiddle.net/80op2y19/ 链接-https: //jsfiddle.net/80op2y19/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.