admin管理员组文章数量:1279214
My website cannot show the prices for different product options and I found the following error message on Chrome inspection:
Uncaught SyntaxError: Unexpected identifier
It is pointing to the line below:
var first_variant_price = $('ul li input[type='radio']:checked').attr('data-price');
This is the plete script:
<script type='text/javascript' charset='utf-8'>
$(document).ready(function(){
var first_variant_price = $('ul li input[type='radio']:checked').attr('data-price');
$('.current-price').text( first_variant_price );
$('input[type='radio']').click(function() {
var variant_price = $(this).attr('data-price');
$('.current-price').text( variant_price);
});
});
</script>
I could not realize any mismatch on this code. Thanks for the help!
My website cannot show the prices for different product options and I found the following error message on Chrome inspection:
Uncaught SyntaxError: Unexpected identifier
It is pointing to the line below:
var first_variant_price = $('ul li input[type='radio']:checked').attr('data-price');
This is the plete script:
<script type='text/javascript' charset='utf-8'>
$(document).ready(function(){
var first_variant_price = $('ul li input[type='radio']:checked').attr('data-price');
$('.current-price').text( first_variant_price );
$('input[type='radio']').click(function() {
var variant_price = $(this).attr('data-price');
$('.current-price').text( variant_price);
});
});
</script>
I could not realize any mismatch on this code. Thanks for the help!
Share Improve this question asked Oct 16, 2012 at 11:51 ValladãoValladão 3475 silver badges18 bronze badges2 Answers
Reset to default 5If you use quotes inside other quotes, either use a different type or escape them:
$("ul li input[type='radio']:checked") // different type of quotes
or
$('ul li input[type=\'radio\']:checked') // escape inner quotes via backslash
but the easiest way is to not quote the radio
at all - it's not necessary.
$('ul li input[type=radio]:checked')
You have problems with quotes. You may either escape \'
the quotes around radio
or simply change the code as follows:
// -.---------------------------------.
v v
$("ul li input[type='radio']:checked").attr('data-price');
本文标签: javascriptJquery Uncaught SyntaxError Unexpected identifierStack Overflow
版权声明:本文标题:javascript - Jquery: Uncaught SyntaxError: Unexpected identifier - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741221168a2360999.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论