Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Javascript 如何在jQuery的面板中追加行?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何在jQuery的面板中追加行?

Javascript 如何在jQuery的面板中追加行?,javascript,jquery,html,Javascript,Jquery,Html,您能告诉我如何在面板中追加行,这是可折叠行(可以展开),我可以追加但不能展开 我在执行此步骤时遇到此错误。首先单击0上的图标){ $(this.addClass('parent'); } }); $('.tree li.parent>a')。在('click',函数(){ //警报('--') $(this.parent().toggleClass('active'); $(this).parent().children('ul').slideToggle('fast'); }); } 这是您的


您能告诉我如何在面板中追加行,这是可折叠行(可以展开),我可以追加但不能展开

我在执行此步骤时遇到此错误。首先单击0上的图标){ $(this.addClass('parent'); } }); $('.tree li.parent>a')。在('click',函数(){ //警报('--') $(this.parent().toggleClass('active'); $(this).parent().children('ul').slideToggle('fast'); }); }
这是您的代码

函数addInmenu(id){
var menuid=“菜单”+id;
//var data=$('#menuId li').html();
$(“#menuId li:first”).append(“
  • ”); //$('ultest').listview('refresh'); 附加菜单(id); });
更新:


这里有更新的提琴供参考

你到底想做什么,要追加的行应该作为子菜单或新菜单项添加?我希望它应该是第一级的子菜单,它应该是第一级前面的+位。当它展开时,它有与计数相同的子菜单row@dave如果有3行超出了理解的输出,请检查更新。用jsfiddle检查我的答案。如果你喜欢的话,一定要回答。谢谢你的回答是正确的。但是为什么在添加新项目时它会崩溃呢
function addInmenu(id){
 alert(id)   
     var menuid="menu_"+id;
    // var data = $('#menuId li').html();
 $('#menuId  li').append('<ul><li id=' + menuid + '><a>'+menuid+'</a></li></ul>');
     $('.tree li').each(function () {
        if ($(this).children('ul').length > 0) {
            $(this).addClass('parent');
        }
    });
$('.tree li.parent > a').on('click',function () {
    //alert('--')
        $(this).parent().toggleClass('active');
        $(this).parent().children('ul').slideToggle('fast');
    });

}
function addInmenu(id){ 
   var menuid="menu_"+id;
   // var data = $('#menuId li').html();

   $('#menuId li:first ').append('<ul><li id=' + menuid + '><a>'+menuid+'</a></li> </ul>');
   $('.tree li').each(function () {
     if ($(this).children('ul').length > 0) {
        $(this).addClass('parent');
     }
   });
   $('.tree li.parent > a').unbind("click");
   $('.tree li.parent > a').on('click',function () {
   //alert('--')
    $(this).parent().toggleClass('active');
    $(this).parent().children('ul').slideToggle('fast');
   });
}


$('#add').click(function () {
  var listItems = $("#ultest").children();
  var id;
  if (typeof ($("#ultest li:last").attr('id')) == 'undefined') {
    //alert('undefint');
    id = "tc_1"
  } else {
    id = $("#ultest li:last").attr('id');
    var index = id.indexOf("_");
    var count = id.substring(index + 1, id.length)
    count = parseInt(count);


    id = id.substring(0, index) + "_" + parseInt(count + 1);
   // alert(id)
  }

  if ($('.tree li.parent').hasClass('active')){        
    $('.tree li.parent').toggleClass('active');
    $('.tree li.parent').children('ul').slideToggle('fast');
  }
  $('#ultest').append('<li id=' + id + '><a href="#" class="foo">' + id + '</a></li>');
    //$('#ultest').listview('refresh');
    addInmenu(id);
});