jquery动态添加元素,报错。请问这个问题怎么处理。
firebug 提示错误如下。HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy
我的目的是想动态的做一棵树。
我的目的是想动态的做一棵树。
<html>
<head>
<script type="text/javascript" src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_f2fb5194.js"></script>
</head>
<body>
<div id="nestable_dep" class="nestable-white dd"></div>
<script type="text/javascript">
jQuery(document).ready(function() {
var Depelm = $("#nestable_dep");
var data=[{"SystemUsers":[],"Id":1,"Code":"123","Name":"123","ParentId":1,"Description":"","State":1},{"SystemUsers"
:[],"Id":2,"Code":"1232","Name":"123","ParentId":1,"Description":"","State":1},{"SystemUsers":[],"Id"
:3,"Code":"12321","Name":"1231","ParentId":2,"Description":"","State":1},{"SystemUsers":[],"Id":4,"Code"
:"2343","Name":"2343","ParentId":2,"Description":"","State":1},{"SystemUsers":[],"Id":5,"Code":"222"
,"Name":"222","ParentId":2,"Description":"","State":1},{"SystemUsers":[],"Id":6,"Code":"qwe","Name":"www"
,"ParentId":2,"Description":"","State":1}]
var dom = document.createElement("ol");
$(dom).addClass("dd-list");
Depelm.append(dom);
$.each(data, function(index, value) {
var item = document.createElement("li");
$(item).addClass("dd-item").attr("data-id", value.Id);
var itemDiv = document.createElement("div");
$(itemDiv).addClass("dd-handle").text(value.Name);
$(item).append(itemDiv);
var hasChild = Depelm.find("[data-id='" + value.ParentId + "']");
if (hasChild.length > 0) {
var cdol = $(hasChild[0]).children("ol:first");
if (cdol.length > 0) {
$(cdol[0]).append(item);
} else {
var cpol = $(hasChild[0]);
cpol.append(dom);
cpol.children("ol:first").append(item);
}
} else {
Depelm.children("ol:first").append(item);
}
});
});
</script>
</body>
</html>
...全文
相关推荐
jquery live()调用不存在的解决方法
在新版的jquery中,live()方法已经被删除了,所以我们在调用的时候会提示该函数不存在,js报错。 解决方法是使用on()函数替换, 原来的写法是: 如果直接替换为on()方法,那么新生成的元素再次点击事件的时候不会有任何效果,新的语法是: 这里涉及到一个问题,$(“body”)这里为什么是body,其实我们可以选择其他的距离#company_logo更近的节点,这样会有更好的性能,其实on()是在body中找#company_logo节点,所以我们吧body换成#company_logo的上级节点会取得更好的性能
解决Layui 表单提交数据为空的问题
今天小编就为大家分享一篇解决Layui 表单提交数据为空的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
jquery表单验证
jquery表单验证,jquery实现各种各类的无刷新表单验证。
IE中关于使用innerHTML加入HTML代码的问题
innerHTML属性在原生javascript中被用于在一个标签内部加入HTML代码,但在IE下面就不适用了,下面有个示例代码,大家可以参考下
树形插件引用问题
网页引用问题,谢谢您的帮忙和解决。。谢谢~


