1

我在生成 div 类的 jQuery 中有以下代码

if (!tst.g.ltContainer) {
      tst.g.ltContainer = $('<div>').addClass('tst-lt-container').addClass('tst-overflow-hidden').css({
        width: inner.width(),
        height: inner.height()
      }).prependTo(inner);
    }
    else {
      tst.g.ltContainer.empty().css({
        width: inner.width(),
        height: inner.height()
      });
    }

然后将使用以下内容将其包装在另一个 div 中:

$(el).find('.tst-layer').wrapAll('<div class="tst-inner"></div>');

因为要让这个脚本工作是通过将东西添加到 html 中它工作得很好......现在我必须创建它以便它与 XML 一起工作......

问题如下:

在解析 xml 时,我正在创建所有需要的 div……问题是这个没有被构建。

这是我写的:

$(xml).find('first').each(function() {

        var container = $('<div></div>').appendTo(body);
        container.attr("id", "test-container");

        var first_style = $(this).attr('template.first.style');

        var first = $('<div></div>').appendTo(container);
        spot.attr("id", "placeholder");
        spot.attr("style", first_style);

        $(xml).find('second').each(function() {
            var second_style = $(this).attr('template.second.style');

            var second= $('<div></div>').appendTo(first);
            second.addClass("tst-layer");
            second.attr("style", second_style);

            var bg_src = $(this).attr('background');
            var background = $('<img/>').appendTo(item);
            background.addClass("tst-bg");
            background.attr("src", bg_src);
        })
    });

这就是通过浏览器返回的内容

     <div id="test-container">
<div id="placeholder" class="tst-container" style="width: 1906px; height: 953px; margin: 0px auto; visibility: visible;">
<div class="tst-inner" style="background-color: transparent; width: 1906px; height: 953px;">
<div class="tst-layer" style="width: 1906px; height: 953px; visibility: visible; display: none;">

实际上它应该返回以下内容

<div id="test-container">
<div id="placeholder" class="tst-container" style="width: 1906px; height: 953px; margin: 0px auto; visibility: visible;">
<div class="tst-inner" style="background-color: transparent; width: 1906px; height: 953px;">
<div class="tst-lt-container tst-overflow-hidden" style="width: 1906px; height: 953px;">
<div class="tst-layer" style="width: 0px; height: 960px; visibility: visible; display: none; left: 0px; right: auto; top: 0px; bottom: auto;">

当 tst-inner 时,如何将 tst-lt-container 放置在 tst-inner 中?

4

0 回答 0