首页 > 解决方案 > 当我们向卡片添加 3 个产品时,我想在产品名称中添加 x 和 3?

问题描述

当我们向卡片添加 3 个产品时,我想在产品名称中添加x和?3例如:Product Name x 3


if(checkGreatrThan(quantity)){
      tableRow +='<div  class="prod-title-col order-summary-col2 '+lastIndex+'"><h3 class="prod-title" >'+ value.product_name + '<span>'+ 'x '+value.quantity+'</span>+'</h3></div>' ;
 }
  else {
     tableRow +='<div  class="prod-title-col order-summary-col2 '+lastIndex+'"><h3 class="prod-title" >'+ value.product_name +'</h3></div>';
}

你能格式化声明吗?

标签: javascriptjqueryxslt

解决方案


我假设您的变量已定义。

您的问题是,您在第一次添加 tableRow 时有一些 ' 和 + 太多。所以你的javascript抛出了那个错误。

if(checkGreatrThan(quantity)){
  tableRow +='<div  class="prod-title-col order-summary-col2 '+lastIndex+'"><h3 class="prod-title" >'+ value.product_name + '<span>x '+value.quantity+'</span></h3></div>' ;
 }
  else {
 tableRow +='<div  class="prod-title-col order-summary-col2 '+lastIndex+'"><h3 class="prod-title" >'+ value.product_name +'</h3></div>';
}


推荐阅读