English 中文(简体)
jQuery,数组,HTML,追加
原标题:jquery, array , html , append

我想把“div”放在“li”中的HTML中。

这是我的HTML代码:

<ul class="NewContent">

    </ul>   
        <div class="test">
            <span>Text1</span>
        </div>

        <div class="test">
            <span>Text2</span>
        </div>

并且jQuery(不确定是否已开始):

<script type="text/javascript">
        $(document).ready(function(){
            $( ul.NewContent ).append("<li>"+ $( .test ).html()+"</li>");
        });
    </script>

但问题是,我想在新的“li”中增加每个“div”内容。

类似于这样的东西:

产出:

<ul class="NewContent">
            <li><span>Text1</span></li>
            <li><span>Text2</span></li>
        </ul> 

现在不好......我需要添加数组或类似的东西。

谢谢!! (Xièxiè!!)

www.un.org/Depts/DGACM/index_spanish.htm 职业介绍 我的混淆描述!

最佳回答

这样应该可以了:

$(function() {
    $( .test ).each(function() {
        $( ul.NewContent ).append( <li> +$(this).html()+ </li> );
        $(this).remove();
    });
});
问题回答

尝试一下:

$(function() {
  $( ul.NewContent ).html($.map($( div.test ), function(i, div) {
    return  <li>  + $(div).html() +  </li> ;
  }).get().join(  ));
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签