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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

If 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