Javascript 附加时jquery中参数列表后的SyntaxError:缺少)

Javascript 附加时jquery中参数列表后的SyntaxError:缺少),javascript,jquery,Javascript,Jquery,我犯了这个错误!缺少)即使我的jquery行中似乎没有任何错误 $('.product_area').append(' <div class="product"> <a href="/index.php?store='+$store_username+'&view=single&product='+json[i].product_id'"><div class="product-image"> <img src="<

我犯了这个错误!缺少
即使我的jquery行中似乎没有任何错误

$('.product_area').append('
 <div class="product">
   <a href="/index.php?store='+$store_username+'&view=single&product='+json[i].product_id'"><div class="product-image">
    <img src="<?php echo image_check('+json[i].product_image1+'); ?>" />
    </div>
    </a>
  <div class="product_details"><div class="product-name">
 <a class="name" href="/index.php?store='+$store_username+'&view=single&product='+json[i].product_id'">
 <span><?php echo substr('+json[i].product_name+',0,23); ?></span>
 </a>
 </div>
  <div class="product-price">
 <span class="price">@ Rs. <?php echo number_format('+json[i].product_price+',2); ?></span>/-</div>
  <div class="product-discount">
 <span class="discount">Discount: 
 <span class="color-text"><?php echo '+json[i].product_discount+' ?></span>%</span>
 </div>
 </div>
 </div>').animate({width:'toggle'},150);
$('.product_area')。追加('
@卢比/-
折扣:
%
动画({width:'toggle'},150);

我试着把它写得尽可能干净。谁能检查一下!这让人非常恼火

这看起来像是在多行上拆分字符串的问题。(正如其他人评论的那样,你也有一个输入错误。如果这是你代码中的错误,你需要修复它,但如果这只是一个输入错误,那么这就是你面临的另一个问题)

有几种方法可以解决这个问题

1)如果可以使用ES6,考虑使用带有“(后台)的字符串模板)。此解决方案可能如下所示:

let html = `<div class="product">
           <a href="/index.php?store=${store_username}&view=single&product...`
var html = '<div class="product">';
html += '<a href="/index.php?store=';
html +=  $store_username;
html +=  '&view=single&product=';
3) 最后,您可以使用\

... .append('<div class="product"> \
           <a href="/index.php?store= \
           '+$store_username+'&view=single&product=' ... );
。附加('\

这看起来像是将字符串拆分为多行时出现的问题。(正如其他人所评论的,您也有一个输入错误。如果这是代码中的错误,您需要修复它,但如果这只是一个输入错误,那么这就是您面临的另一个问题)

有几种方法可以解决这个问题

1)如果可以使用ES6,考虑使用带有“(后台)的字符串模板)。此解决方案可能如下所示:

let html = `<div class="product">
           <a href="/index.php?store=${store_username}&view=single&product...`
var html = '<div class="product">';
html += '<a href="/index.php?store=';
html +=  $store_username;
html +=  '&view=single&product=';
3) 最后,您可以使用\

... .append('<div class="product"> \
           <a href="/index.php?store= \
           '+$store_username+'&view=single&product=' ... );
。附加('\
换行

<a href="/index.php?store='+$store_username+'&view=single&product='+json[i].product_id'"><div class="product-image">


更改此行

<a href="/index.php?store='+$store_username+'&view=single&product='+json[i].product_id'"><div class="product-image">


这个怎么样

$('.product_area').append('<div class="product">\
    <a href="/index.php?store=\'+$store_username+\'&view=single&product=\'+json[i].product_id\'"><div class="product-image">\
        <img src="<?php echo image_check(\'+json[i].product_image1+\'); ?>" />\
        </div>\
        </a>\
    <div class="product_details"><div class="product-name">\
    <a class="name" href="/index.php?store=\'+$store_username+\'&view=single&product=\'+json[i].product_id\'">\
    <span><?php echo substr(\'+json[i].product_name+\',0,23); ?></span>\
    </a>\
    </div>\
    <div class="product-price">\
    <span class="price">@ Rs. <?php echo number_format(\'+json[i].product_price+\',2); ?></span>/-</div>\
    <div class="product-discount">\
    <span class="discount">Discount: \
    <span class="color-text"><?php echo \'+json[i].product_discount+\' ?>    </span>%</span>\
    </div>\
    </div>\
    </div>').animate({width:'toggle'},150);
$('.product_area')。追加('\
\
\
\
\
\
@卢比/-\
\
折扣:\
%\
\
\
动画({width:'toggle'},150);
这个怎么样

$('.product_area').append('<div class="product">\
    <a href="/index.php?store=\'+$store_username+\'&view=single&product=\'+json[i].product_id\'"><div class="product-image">\
        <img src="<?php echo image_check(\'+json[i].product_image1+\'); ?>" />\
        </div>\
        </a>\
    <div class="product_details"><div class="product-name">\
    <a class="name" href="/index.php?store=\'+$store_username+\'&view=single&product=\'+json[i].product_id\'">\
    <span><?php echo substr(\'+json[i].product_name+\',0,23); ?></span>\
    </a>\
    </div>\
    <div class="product-price">\
    <span class="price">@ Rs. <?php echo number_format(\'+json[i].product_price+\',2); ?></span>/-</div>\
    <div class="product-discount">\
    <span class="discount">Discount: \
    <span class="color-text"><?php echo \'+json[i].product_discount+\' ?>    </span>%</span>\
    </div>\
    </div>\
    </div>').animate({width:'toggle'},150);
$('.product_area')。追加('\
\
\
\
\
\
@卢比/-\
\
折扣:\
%\
\
\
动画({width:'toggle'},150);

您不能将字符串拆分为多行。您需要将其连接起来,或在行的末尾使用\。您还试图将JS数据附加到PHP中,这将永远不会起作用。问题的原因是
+
之后缺少
json[i].product_id
。投票以键入方式结束。您不能在“'''”或“''之间转到新行`。这看起来很混乱。可能是重复的。您无法在多行上拆分字符串。您需要将其连接起来,或在行的末尾使用\。您还试图将JS数据附加到PHP中,这将永远不会起作用。问题的原因是
+
之后缺少
json[i].product\u id
。投票以键入方式结束。您不能转到“''`或“''`之间的新行。这看起来很混乱,可能重复了SyntaxError:JSON.parse:JSON数据
\'+JSON[i]的第1行第2列中的意外字符.product\u price+\'
可能不应转义。语法错误:JSON.parse:JSON数据
\'+JSON[i]第1行第2列的意外字符。product\u price+\'
可能不应转义。