当我使用dtree创建树形结构时,以下是我的代码:
<div id="combdtree" class="dtreecob">
<div class="dtree" style="overflow: auto; width: 100%;">
$.ajax({
url : "${ctxPath}/type/list",
dataType : 'text',
type : 'get',
async : false,
success : function(data) {
var obj = JSON.parse(data);
for (var i = 0; i < obj.length; i++) {
tree.add(obj[i].id, obj[i].pid, obj[i].name,
// "javascript:setSrcValue(/''+ obj[i].name + '/',/''+ obj[i].pid+ '/')"
);
}
document.write(tree);
}
});
}
loadData();
</script>
<div class="dBottom"><a href="javascript:hiddenDTree();" mce_href="javascript:hiddenDTree();">关闭</a></div>
var srcElement = null;
var valueElement = null;
function showTree(item,valueId){
srcElement = window.event.srcElement;
valueElement = document.getElementById(valueId);
var x = getLeft(item);
var y = getTop(item) + item.offsetHeight;
var w = item.offsetWidth;
blockDTree(x,y,w);
}
function getTop(e){
var offset=e.offsetTop;
if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
return offset;
}
function getLeft(e){
var offset=e.offsetLeft;
if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
return offset;
}
function blockDTree(x,y,w){
var item = document.getElementById("combdtree");
item.style.display = 'block';
item.style.top = y;
item.style.left = x;
}
function hiddenDTree(){
var item = document.getElementById("combdtree");
if(item){
item.style.display = 'none';
}
}
function setSrcValue(text,value){
srcElement.value = text;
valueElement.value = value;
hiddenDTree();
}
以下是我的错误:
Home:731 Uncaught TypeError: Cannot read property 'style' of null
2VM11474:1 Uncaught ReferenceError: addNodes is not defined
我发现了一些相同的错误,但是我没有找到解决它的好方法。如何更正它? Js对我来说是新的。第二个错误可能与window.addNode有关,但我不知道如何使用它?