Jquery .append 语法

标签 jquery append

我有一个 Coldfusion 网站,其中包含 10000 多种产品。如果我使用普通的 cfquery 加载具有超过 1000 条记录的特定 sub_cat_id 的产品,则页面需要永远加载并减慢速度,因此我使用 JSON 格式返回结果。我遇到的问题是将返回的结果 append 到页面上的特定 div 中。我知道某处存在语法错误,但我想知道在使用追加函数时如何以及何时使用“”或+。这是我的 append 函数代码:

// Read the products
$.ajax({
url: "js/gtprod.cfm?filter=brand&brand_id=115",
dataType: "json",
success: function(data) {
  var row, sData, _len, _i;
  // Run the data thru queryToObject
  data = queryToObject(data);
  // Convert the object to a string to display it
  sData = JSON.stringify(data);

  // Print all products
  $('#product').append('<h3>PRODUCTS:</h3>');
  // Loop over the query
  for (_i = 0, _len = data.length; _i < _len; _i++) {
    row = data[_i];
    $('#main').append('<div id="product" class="mix' + row.make_title + row.model_title +'" data-name="'+ row.product_title +'"><div id="productleft"></div><div id="productright"> '<h3 align="left">' + '<a href="products-detail.cfm?product_id=' + row.product_id + '">' + row.product_title + '</a>' + '</h3>'<div align="left" id="productrightmidsection" >VEHICLE: + '<span>' + row.make_title + '-' + row.model_title + '</span>' + '|' + 'Manufacturer:' + '<span>' + row.brand_name + '</span>' <div id="productview">'<a href="products-detail.cfm?product_id=' + row.product_id + '" class="productview">' + View &raquo; + '</a>'</div></div></div></div>' );
  }
}
});

最佳答案

使用这个,你会遇到串联问题

    $('#main').append('<div id="product" class="mix' + row.make_title + row.model_title +'" data-name="'+ row.product_title +'"><div id="productleft"></div><div id="productright"> <h3 align="left"><a href="products-detail.cfm?product_id=' + row.product_id + '">' + row.product_title + '</a></h3><div align="left" id="productrightmidsection" >VEHICLE: <span>' + row.make_title + '-' + row.model_title + '</span> | Manufacturer: <span>' + row.brand_name + '</span> <div id="productview"><a href="products-detail.cfm?product_id=' + row.product_id + '" class="productview"> View &raquo; </a></div></div></div></div>' );

关于Jquery .append 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20814775/

相关文章:

javascript - 使用自己的文本更新所有 span 元素的内容

python - 使用多处理 append 到同一列表 - python

jQuery:在 WebKit(Chrome/Safari) 中使用带有 anchor 链接的 Append()

Python:如何合并两个列表,如带有 for 循环的 zip

javascript - 将 jQuery (Json) 中的日期时间附加到表中

javascript - 使用 javascript/jquery 将我的网页焦点转移到浏览器地址栏

javascript - 我如何使用全局变量来隐藏/显示使用 jQuery 的 div

javascript - 如何显示 JSON 数据中的图像 URL?

javascript - Jquery - 删除 append 代码不起作用

python - 在 pandas/python 的同一数据框中将两列合并为一列