Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jQuery中为ul列表中的父子关系获取树结构?_Jquery - Fatal编程技术网

如何在jQuery中为ul列表中的父子关系获取树结构?

如何在jQuery中为ul列表中的父子关系获取树结构?,jquery,Jquery,以前 试一试 jQuery(函数($){ 变量$ul=$('ul'); $ul.find('li[父id]”)。每个(函数(){ $ul.find('li[parent id='+$(this).attr('li-id'+']).wrapAll('')).parent().appendTo(this) }); }) 演示:试试看 jQuery(function($){ var $ul = $('ul'); $ul.find('li[parent-id]').each(funct

以前

试一试

jQuery(函数($){
变量$ul=$('ul');
$ul.find('li[父id]”)。每个(函数(){
$ul.find('li[parent id='+$(this).attr('li-id'+']).wrapAll('
    ')).parent().appendTo(this) }); })
演示:

试试看

jQuery(function($){
    var $ul = $('ul');
    $ul.find('li[parent-id]').each(function () {
        $ul.find('li[parent-id=' + $(this).attr('li-id') + ']').wrapAll('<ul />').parent().appendTo(this)
    });
})
jQuery(函数($){
变量$ul=$('ul');
$ul.find('li[父id]”)。每个(函数(){
$ul.find('li[parent id='+$(this).attr('li-id'+']).wrapAll('
    ')).parent().appendTo(this) }); })
演示:

试试看

jQuery(function($){
    var $ul = $('ul');
    $ul.find('li[parent-id]').each(function () {
        $ul.find('li[parent-id=' + $(this).attr('li-id') + ']').wrapAll('<ul />').parent().appendTo(this)
    });
})
$(“li”)。每个(函数(){
var ul=$(“
    ”); ul.append($(“[parent id=“+$(this).attr(“li id”)+”]))); $(此)。附加(ul); });
试试看

jQuery(function($){
    var $ul = $('ul');
    $ul.find('li[parent-id]').each(function () {
        $ul.find('li[parent-id=' + $(this).attr('li-id') + ']').wrapAll('<ul />').parent().appendTo(this)
    });
})
$(“li”)。每个(函数(){
var ul=$(“
    ”); ul.append($(“[parent id=“+$(this).attr(“li id”)+”]))); $(此)。附加(ul); });
$(“li”)。每个(函数(){
var lid=$(this.attr(“li id”);
var pid=$(this.attr(“父id”);
var li=$(本);
如果(pid!=0){
//警报(pid);
var theli=$(“li”).filter(“[LIID=””+pid+“]”);
如果(第三方查找(“ul”)长度>0){
theli.find(“ul”).append(“
  • $("li").each(function(){
     var ul=$("<ul/>");
     ul.append($("[parent-id="+$(this).attr("li-id")+"]"));
     $(this).append(ul);
    
    });
    
        $("li").each(function () {
        var lid = $(this).attr("li-id");
        var pid = $(this).attr("parent-id");
        var li = $(this);
        if (pid != 0) {
           // alert(pid);
            var theli = $("li").filter("[li-id='" + pid + "']");
            if (theli.find("ul").length > 0) {
                theli.find("ul").append("<li parent-id='" + pid + "' li-id='" + lid + "'>" + li.html() + "</li>");
            } else {
                theli.html("<ul></ul>");
                theli.find("ul").append("<li parent-id='" + pid + "' li-id='" + lid + "'>" + li.html() + "</li>");
    
            }
            li.remove();
        }
    });