将函数初始化为特定div

时间:2022-05-08 18:14:51

I have this code

我有这个代码

var wrapper = {
          init: function (elemClass) {
            this.className = elemClass || '.full-description';
            this.wrapElems();
          },
          wrapElems: function () {
            var $lines = $(this.className),
                holder = [];

            $lines.each(function (i, item) {
              holder.push(item);

              if (holder.length === 2) {
                $(holder).wrapAll('<div class="w-row" />');
                holder.length  = 0;
              }
            });

            $(holder).wrapAll('<div class="w-row" />');
          }
        };

    wrapper.init();

I want to init the wrapper into a specific div, I try this

我想将包装器初始化为特定的div,我试试这个

var init = wrapper.init();
$("#div-content").append(init);

It does not work. Thanks for the help

这是行不通的。谢谢您的帮助

1 个解决方案

#1


you can append like this

你可以像这样追加

$("#div-content").append("<script>wrapper.init();</script>");

#1


you can append like this

你可以像这样追加

$("#div-content").append("<script>wrapper.init();</script>");