<div id="tree1" class="tree-folder-content"> <div class="tree-folder">1</div> <div class="tree-folder">1</div> <div class="tree-folder">1</div> <div class="tree-folder">1</div> <div class="tree-folder">1</div> </div>
获取class="tree-folder"的 div个数
function add() { var count = $("#tree3 >.tree-folder").size() + 1;//获取class="tree-folder"的个数 var htmls = '<div class="tree-folder 3t' + count + '"style="display: block;"><div class="tree-folder-header" ><i class="icon-folder-open"></i><div class="tree-folder-name">我靠<div class="tree-actions"><i class="icon-remove" onclick="remove3(' + count + ')"></i> <i class="icon-edit" onclick="edit1()"></i></div></div></div><div class="tree-folder-content"></div></div>'; $('#tree1').append(htmls); }