错误: '$.fn.zTree' 为空或不是对象 急在线等
<link rel="stylesheet" type="text/css" href="../css/all.css" />
<link rel="stylesheet" type="text/css" href="../css/index.css" />
<link rel="stylesheet" type="text/css" href="../css/xitong.css" />
<link href="../css/Common.css" rel="stylesheet" type="text/css" />
<link href="../sysScripts/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<link href="../sysScripts/ztree/css/Filetree.css" rel="stylesheet" type="text/css" />
<script src="../sysScripts/jquery/1.7.2/Jquery.js" type="text/javascript"></script>
<script src="../sysScripts/ztree/js/jquery.ztree.all-3.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
var setting = {
check: {
enable: true
//chkboxType: {"Y":"Ps", "N":"Ps"}
},
view: {
selectedMulti: false
},
data: {
simpleData: {
enable: true
}
},
callback: {
beforeClick: beforeClick,
onCheck: onCheck
}
};
var setting2 = {
data: {
simpleData: {
enable: true
}
}
};
var zNodes = <% =BuildSectionTree() %>;
var zNodes2source = [<% =strPermissionsText %>];
var zNodes2=zNodes2source;
function beforeClick(treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("treeSection");
zTree.checkNode(treeNode, !treeNode.checked, null, true);
return false;
}
var zTree;
function onCheck(e, treeId, treeNode) {
//轮询所有选中的根节点
zTree = $.fn.zTree.getZTreeObj("treeSection");
var nodes = zTree.getNodes();
var v = "",
vhidden="";
for (var i=0;i<nodes.length; i++) {
if(nodes[i].checked==true)
{
v+=buildNodes(nodes[i])+",";
vhidden+=buildNodesSid(nodes[i]);
}
}
if (v.length > 0 ) v = v.substring(0, v.length-1);
$("#selectSectionvalue").val(v);
if (vhidden.length > 0 ) vhidden = vhidden.substring(0, vhidden.length-1);
$("#sectionCurrentSelect").val(vhidden);
var tempodes=jQuery.parseJSON("["+v+"]");
$.fn.zTree.init($("#selectTreeSelected"), setting2, tempodes);
}
function buildNodes(currentnode) {
if(currentnode.checked!=true)
{
return "";
}
var tempnode = "{";
var tempone='"name":'+'"'+currentnode.name+'",';
if(currentnode.children!=null)
{
if(currentnode.children.length>0)
{
var tt="";
for(var i=0;i<currentnode.children.length;i++)
{
if(currentnode.children[i].checked==true)
{
tt+=buildNodes(currentnode.children[i])+",";
}
}
if (tt.length > 0 ) tt = tt.substring(0, tt.length-1);
tempone+='"children":['+tt+'],';
}
}
tempone+='"isParent":'+currentnode.isParent+',';
tempone+='"open":'+currentnode.open+',';
tempone+='"lifetype":'+'"'+currentnode.lifetype+'",';
tempone+='"sid":'+'"'+currentnode.sid+'"';
tempnode +=tempone+ "}";
return tempnode;
}
function buildNodesSid(currentnode) {
if(currentnode.checked!=true)
{
return "";
}
var tempsid = currentnode.sid+",";
if(currentnode.children!=null)
{
if(currentnode.children.length>0)
{
var tt="";
for(var i=0;i<currentnode.children.length;i++)
{
if(currentnode.children[i].checked==true)
{
tt+=buildNodesSid(currentnode.children[i]);
}
}
tempsid+=tt;
}
}
return tempsid;
}
function updateNode(newNodes) {
var zTree = $.fn.zTree.getZTreeObj("selectTreeSelected"),
nodes = newNodes;console.dir(zTree);
if (nodes.length == 0) {
alert("请先选择栏目");
}
for (var i=0, l=nodes.length; i<l; i++) {
zTree.updateNode(nodes[i]);
}
}
function showMenu() {
var cityObj = $("#selectSection");
var cityOffset = $("#selectSection").offset();
$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
$("body").bind("mousedown", onBodyDown);
}
function hideMenu() {
$("#menuContent").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);
}
function onBodyDown(event) {
if (!(event.target.id == "menuBtn" || event.target.id == "selectSection" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
hideMenu();
}
}
$(document).ready(function () {
//判断ie浏览器
if(!+[1,])
{
var pIeJs=document.createElement("script");
pIeJs.src='../../sysCommon/sysScripts/lib/json2.js';
document.appendChild(pIeJs);
};
$.fn.zTree.init($("#treeSection"), setting, zNodes);
$.fn.zTree.init($("#selectTreeSelected"), setting2, zNodes2);
});
</script>
最后2行出现这个错误
4、需要加载 zTreeStyle.css 以及 zTreeStyle 目录下的 img 文件。
5、如果需要使用自定义图标请参考相应的Demo。
6、请注意设置 zTree 的容器样式 class="ztree",其中 "ztree" 这个 className,可以根据需要随意修改,别忘了修改 css 中对应名字就是了,对于容器如果需要增加其他特殊样式,可根据自己的需要进行修改。
详见参考
[解决办法]
你换成 jquery.ztree.core-3.4.js/jquery.ztree.excheck-3.4.js/jquery.ztree.exedit-3.4.js
这3个引用
[解决办法]
js文件有问题