复制代代码如下: <スクリプト src="assets/js/jquery.js"> 复制代代码如下: 复制代码代码如下: <br> var zTree1;<br> var setting = {<br> isSimpleData: true,<br> treeNodeKey: "id",<br> treeNodeParentKey: "pId",<br> fontCss: setFont,<br> callback: {<br> beforeClick: zTreeOnBeforeClick,<br> click: zTreeOnClick<br> } <br> };<br> var zNodes = [<br> {id:1, pId:0, name:"北京"},<br> {id:2, pId:0, name:"天津"},<br> {id:3, pId:0, name:"上海"},<br> {id:6, pId:0, name:"重庆"},<br> {id:4, pId:0, name:"河北省", open:true},<br> {id:41, pId:4, name:"石家庄"},<br> {id:42, pId:4, name:"保定"},<br> {id:43, pId:4, name:"邯郸"},<br> {id:44, pId:4, name:"承德"},<br> {id:5, pId:0, name:"广东省", open:true},<br> {id:51, pId:5, name:"广州"},<br> {id:52, pId:5, name:"深圳"},<br> {id:53, pId:5, name:"东莞"},<br> {id:54, pId:5, name:"佛山"},<br> {id:6, pId:0, name:"福建省", open:true},<br> {id:61, pId:6, name:"福州"},<br> {id:62, pId:6, name:"厦门"},<br> {id:63, pId:6, name:"泉州"},<br> {id:64, pId:6, name:"三明"}<br> ];<br> <p> function setFont(treeId,treeNode) {<br> if (treeNode && TreeNode.isParent) {<br> return {color: "blue"};<br> } else {<br> return null;<br> }<br> }<br> function showMenu(){<br> var cityObj = $("#citySel");<br> var cityOffset = $("#citySel").offset();<br> $( "#DropdownMenuBackground").css({left:cityOffset.left "px",top:cityOffset.top cityObj.outerHeight() "px"}).slideDown("fast"); <br> } <br> function reloadTree(){<br> hideMenu();<br> zTree1 = $("#dropdownMenu").zTree(setting, zNodes);<br> }<br> function hideMenu() {<br> $("#DropdownMenuBackground").fadeOut("fast");<br> }<br> function zTreeOnBeforeClick(treeId,treeNode) {<br> var check = (treeNode && !treeNode.isParent);<br> if (!check)alert("只能选择城市...");<br> return check;<br> }<br><br> function zTreeOnClick(event,treeId,treeNode) {<br> if (treeNode) {<br> var cityObj = $("#citySel");<br> cityObj.attr("value",treeNode.name);<br> hideMenu();<br> }<br> }<br><br> $(document).ready(function(e) {<br> reloadTree();<br> $("#menuBtn").bind("click",<br> function(){<br> if($("#DropdownMenuBackground").css("display") == "none"){<br> showMenu();<br> }<br> else{<br> hideMenu();<br> }<br> }<br> );<br> $("body").bind("mousedown", <br> function(event){<br> if (!(event.target.id == 「ドロップダウンメニューの背景」 " || $(event.target).parents("#DropdownMenuBackground").length>0)) {<br> HideMenu();<br> }<br> }); <br> });<br>