我该如何遍历jQuery代码?当我编码时显示以下错误

时间:2019-02-12 15:09:42

标签: javascript jquery wordpress

我想显示带有排序过滤器和分页的帖子列表。当我反复将容器编码为#container1#container2时,它就起作用了,依此类推,我想循环所有容器以使用mixitup和使用simplePagination js的分页显示排序过滤器

JQuery,JavaScript

   jQuery(document).ready(function(jQuery) {
    // First Column Pagination start from here

    for(var i=0; i< 3; i++){

      function sw_show_pagination(){
        jQuery(function(jQuery) {
          var pageParts = jQuery(".itemContainer-"+i+" .mix");
          var numPages = pageParts.length;
          var perPage = 10;
          pageParts.slice(perPage).hide();
          jQuery(".page-nav-"+i).pagination({
            items: numPages,
            itemsOnPage: perPage,
            prevText:"",
            nextText:"",
            cssStyle: "compact-theme",
            onPageClick: function(pageNum) {
              var start = perPage * (pageNum - 1);
              var end = start + perPage;
              pageParts.hide().slice(start, end).show();
            }
          });
        });
      } //end show pagination

      sw_show_pagination();

      // First Column MixItUp start from here
      var containerEl+i = document.querySelector('[data-ref="itemContainer-'+i+'"]');
      var config+i = { controls: { scope: 'local' } , callbacks: {
        onMixStart: function(state,futureState ){
          jQuery(".page-nav-"+i).pagination('destroy');
        },
        onMixEnd: function(state, futureState){
          jQuery(".page-nav-"+i).pagination('redraw');
        }
      }};

      var mixer+i = mixitup(containerEl+i,config+i);

    }

  }); 
  

控制台错误SyntaxError:意外令牌:“ +”

在线 enter image description here

1 个答案:

答案 0 :(得分:0)

在变量名中使用'+'是非法的。

更改以下内容:

ContainerEl + i

config + i

mixer + i

jQuery(document).ready(function(jQuery) {
// First Column Pagination start from here

for(var i=0; i< 3; i++){

function sw_show_pagination(){
jQuery(function(jQuery) {
var pageParts = jQuery(".itemContainer-"+i+" .mix");
var numPages = pageParts.length;
var perPage = 10;
pageParts.slice(perPage).hide();
jQuery(".page-nav-"+i).pagination({
items: numPages,
itemsOnPage: perPage,
prevText:"",
nextText:"",
cssStyle: "compact-theme",
onPageClick: function(pageNum) {
var start = perPage * (pageNum - 1);
var end = start + perPage;
pageParts.hide()
.slice(start, end).show();
}
});
});

} //end show pagination

sw_show_pagination();

// First Column MixItUp start from here
var containerEli = document.querySelector('[data-ref="itemContainer-'+i+'"]');
var configi = { controls: { scope: 'local' } , callbacks: {
onMixStart: function(state,futureState ){
jQuery(".page-nav-"+i).pagination('destroy');
},
onMixEnd: function(state, futureState){
jQuery(".page-nav-"+i).pagination('redraw');
}
} };
var mixeri = mixitup(containerEli,configi);

}

});