jquery和html中的表分页

时间:2016-07-29 07:42:59

标签: javascript jquery html pagination

我正在尝试对以下代码进行分页。使用JavaScript将数据添加到表中。任何人都可以帮我解决这个问题吗?

任何添加或重写代码都会有所帮助。

function onDeviceReady() {
  var queryquery =
    var bestbuy = "";
  jQuery.getJSON(queryquery, function(resultsbestbuy) {
    var productstopdeal = JSON.parse(resultsbestbuy);
    bestbuy += "<div class=\"table-container\">" + "<table class=\"table table-filter\">";
    for (i = 0; i < productstopdeal.Products.length; i++) {

      bestbuy += "<tbody>" + "<tr>" + "<td>" + "<div class=\"ckbox\">" + "<input type=\"checkbox\" id=\"checkbox1\">" + "<label for=\"checkbox1\"></label>" + "</div>" + "</td>" + "<td>" + "<a href=\"javascript:;\" class=\"star\">" + "<i class=\"glyphicon glyphicon-star\"></i>" + "</a>" + "</td>" + "<td>" + "<div class=\"media\">" + "<a href=";
      var pId = urlEncode(productstopdeal.Products[i].Id);
      bestbuy += pId;

      bestbuy += " class=\"pull-left\">" + "<img src=" + productstopdeal.Products[i].DefaultPictureModel.ImageUrl + " class=\"media-photo\" style=\"height:120px; width:120px;\">" + "</a>" + "<div>" + "<p>" + "<strong><small><strike>MRP:&nbsp;Rs.&nbsp;" + +"/-" + "</strike><br />Offer&nbsp;price:&nbsp;Rs.&nbsp;" + +"/-<br />You&nbsp;save:&nbsp;Rs.&nbsp;" + +"/-</small></strong>" + "</p>" + "</div>" + "<div class=\"media-body\">" + "<p>" + +"</p>" + "</div>" + "<button class=\"btn btn-success\" type=\"button\" id=\"addToCartButton\"><span class=\"glyphicon glyphicon-shopping-cart\"></span> BUY NOW</button>" + "</div>" + "</td>" + "</tr>" + "</tbody>" + "</table>";
    }
    bestbuy += "</div>";
    $('#bestBuy').html(bestbuy);
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="bestBuy"></div>

1 个答案:

答案 0 :(得分:0)

根据我的理解纠正了代码。

jQuery.getJSON(queryquery, function (resultsbestbuy) {
    var bestbuy = "";

var productstopdeal = JSON.parse(resultsbestbuy);

bestbuy += "<div class=\"table-container\">"
                          + "<table class=\"table table-filter\"><tbody>";
for (i = 0; i < productstopdeal.Products.length; i++) {

    bestbuy +=  "<tr>"
                                 + "<td>"
                                        + "<div class=\"ckbox\">"
                                        + "<input type=\"checkbox\" id=\"checkbox1\">"
                                            + "<label for=\"checkbox1\"></label>"
                                        + "</div>"
                                    + "</td>"
                                    + "<td>"
                                        + "<a href=\"javascript:;\" class=\"star\">"
                                            + "<i class=\"glyphicon glyphicon-star\"></i>"
                                        + "</a>"
                                    + "</td>"
                                    + "<td>"
                                        + "<div class=\"media\">"
                                            + "<a href='";
    var pId = urlEncode(productstopdeal.Products[i].Id);
       bestbuy += pId;

    bestbuy += "' class=\"pull-left\">"
                        + "<img src='" + productstopdeal.Products[i].DefaultPictureModel.ImageUrl + "' class=\"media-photo\" style=\"height:120px; width:120px;\">"
                    + "</a>"
                    + "<div>"
                        + "<p>"
                            + "<strong><small><strike>MRP:&nbsp;Rs.&nbsp;" + +"/-"
                            + "</strike><br />Offer&nbsp;price:&nbsp;Rs.&nbsp;" + + "/-<br />You&nbsp;save:&nbsp;Rs.&nbsp;" + +"/-</small></strong>"
                        + "</p>"
                    + "</div>"
                    + "<div class=\"media-body\">"
                        + "<p>" + + "</p>"
                    + "</div>"
                    + "<button class=\"btn btn-success\" type=\"button\" id=\"addToCartButton\"><span class=\"glyphicon glyphicon-shopping-cart\"></span> BUY NOW</button>"
                + "</div>"
            + "</td>"
        + "</tr>"
}
bestbuy += "</tbody></table></div>";
$('#bestBuy').html(bestbuy);
});