js多級(jí)樹(shù)形彈出一個(gè)小窗口層(非常好用)實(shí)例代碼

// JScript 文件
var inputID, inputName;
function ExpandSubCategory(iCategoryID, FahterID) {
var li_father = document.getElementById("li_" + iCategoryID);
if (li_father.getElementsByTagName("li").length > 0) //如果已經(jīng)加載了下級(jí)節(jié)點(diǎn)則直接展開(kāi),不必在去讀取數(shù)據(jù)
{
ChangeStatus(iCategoryID);
return;
}
//打開(kāi)時(shí)顯示稍等
switchNote(iCategoryID, true);
//AJAX回調(diào)函數(shù),加載節(jié)點(diǎn)
used_car.BLL.T_BrandBaby.GetList("dm='品牌' and fID=" + iCategoryID, GetSubCategory_callback);
}
function ExpandSubCategoryAgain(iCategoryID, FahterID) {
var li_father = document.getElementById("li_" + iCategoryID);
li_father.className = "Opened";
//打開(kāi)時(shí)顯示稍等
switchNote(iCategoryID, true);
//AJAX回調(diào)函數(shù),加載節(jié)點(diǎn)
used_car.BLL.T_BrandBaby.GetList("dm='品牌' and fID=" + iCategoryID, GetSubCategory_callback);
}
function GetSubCategory_callback(response) {
var dt = response.value.Tables[0];
if (dt.Rows.length > 0) {
var iCategoryID = dt.Rows[0].fID; //父ID
}
var li_father = document.getElementById("li_" + iCategoryID);
var ul_sub = document.getElementById("ulTree_" + iCategoryID);
if (ul_sub != null) {
li_father.removeChild(ul_sub)
}
var ul = document.createElement("ul");
ul.id = "ulTree_" + iCategoryID
for (var i = 0; i < dt.Rows.length; i++) {
if (used_car.BLL.T_BrandBaby.GetList("dm='品牌' and fID=" + dt.Rows[i].id).value.Tables[0].Rows.length<1)
// {
// if (dt.Rows[i].ProductStyle_IsChild == 1) //如果已沒(méi)有下一級(jí)節(jié)點(diǎn)
{
var li = document.createElement("li");
li.className = "Child";
li.id = "li_" + dt.Rows[i].id;
var img = document.createElement("img");
img.id = dt.Rows[i].id;
img.className = "s";
img.src = "../../css/s.gif";
var a = document.createElement("a");
var id = dt.Rows[i].id;
a.href = "javascript:OpenDocument('" + dt.Rows[i].id + "','" + dt.Rows[i].name + "');";
a.innerHTML = dt.Rows[i].name.sub(14);
a.title = dt.Rows[i].name;
}
else //如果還有下級(jí)節(jié)點(diǎn)
{
var li = document.createElement("li");
li.className = "Closed";
li.id = "li_" + dt.Rows[i].id;
var img = document.createElement("img");
img.id = dt.Rows[i].id;
img.className = "s";
img.src = "../../css/s.gif";
img.onclick = function () {
ExpandSubCategory(this.id);
};
img.alt = "展開(kāi)/折疊";
var a = document.createElement("a");
a.href = "javascript:ExpandSubCategory(" + dt.Rows[i].id + ",'editCate');";
a.innerHTML = dt.Rows[i].name.sub(14);
a.title = dt.Rows[i].name;
}
li.appendChild(img);
li.appendChild(a);
ul.appendChild(li);
}
li_father.appendChild(ul);
//先顯示稍等。。。
switchNote(iCategoryID, false);
}
// 葉子節(jié)點(diǎn)的單擊響應(yīng)函數(shù)
function OpenDocument(iCategoryID, Action) {
shut();
// inputName.Value = "asddsafdf"; //修改之前
$(inputName).attr('value', Action); //新添
var thisID = inputName.getAttribute("id");
// alert(inputName.value +":"+ thisID + "--" + Action + "--" + iCategoryID);
inputID.value = iCategoryID;
clienkButton1();
}
function ChangeStatus(iCategoryID) {
var li_father = document.getElementById("li_" + iCategoryID);
if (li_father.className == "Opened") {
li_father.className = "Closed";
}
else {
li_father.className = "Opened";
}
}
function ChangeStatus2(iCategoryID) {
var li_father = document.getElementById("li_" + iCategoryID);
if (li_father.className == "Closed") {
li_father.className = "Opened";
}
}
function switchNote(iCategoryID, show) {
var li_father = document.getElementById("li_" + iCategoryID);
if (show) {
var ul = document.createElement("ul");
ul.id = "ul_note_" + iCategoryID;
var note = document.createElement("li");
note.className = "Child";
var img = document.createElement("img");
img.className = "s";
img.src = "../../css/s.gif";
var a = document.createElement("a");
a.href = "javascript:void(0);";
a.innerHTML = "請(qǐng)稍候...";
note.appendChild(img);
note.appendChild(a);
//ul.appendChild(note);
li_father.appendChild(ul);
}
else {
var ul = document.getElementById("ul_note_" + iCategoryID);
if (ul) {
li_father.removeChild(ul);
}
}
}
function InitTree(obj, idObj, FatherID) {
// 加載根節(jié)點(diǎn)
// writeDiv();
//alert(obj.value + "--" + idObj.value);
inputName=obj;
inputID = idObj;
var pos = getPosition(inputName);
var tree = document.getElementById("cateDivTree");
var root = document.createElement("li");
var objshow = document.getElementById("opencateDiv");
objshow.style.top = pos[1] + pos[3] + "px";
objshow.style.left = pos[0] + "px";
objshow.style.display = "block";
tree.style.display = "block";
root.id = "li_" + FatherID;
tree.appendChild(root);
// 加載頁(yè)面時(shí)顯示第一級(jí)分類(lèi)
ExpandSubCategory(FatherID);
ChangeStatus2(FatherID);
}
writeDiv();
function writeDiv() {
document.write("<div id='opencateDiv' style='position:absolute;display:none;z-index:1000;width:200px;height:250px;'>");
document.write("<div class='divClose'>請(qǐng)選擇分類(lèi) <a href=\"#\" title=\"關(guān)閉\" onclick=\"shut()\">×</a> </div>");
document.write("<div id='cateDivTree' class='TreeMenu' style='display:block;height:250px;overflow :auto;' >");
document.write("</div></div>");
}
function getPosition(obj) {
if (obj) {
var w = obj.offsetWidth;
var h = obj.offsetHeight;
if (obj.offsetParent) {
for (var posX = 0, posY = 0; obj.offsetParent; obj = obj.offsetParent) {
posX += obj.offsetLeft;
posY += obj.offsetTop;
}
return [posX, posY, w, h];
} else {
return [obj.x, obj.y, w, h];
}
} else {
return [0, 0, 0, 0];
}
}
function shut() {
close11();
}
function close11() {
var objshow = document.getElementById("opencateDiv");
objshow.style.display = "none"
objshow.style.top = 0;
objshow.style.left = 0;
}
function Opent11() {
var objshow = document.getElementById("opencateDiv");
objshow.style.display = "block";
}
String.prototype.sub = function (n) {
var r = /[^\x00-\xff]/g;
if (this.replace(r, "mm").length <= n) return this;
n = n - 3;
var m = Math.floor(n / 2);
for (var i = m; i < this.length; i++) {
if (this.substr(0, i).replace(r, "mm").length >= n) {
return this.substr(0, i) + "...";
}
}
return this;
};
2//樣式
.TreeMenu{border:#006600 solid 1px; background-color:#ffffff; height :350px; overflow :auto ; }
.TreeMenu img.s
{
cursor:hand;
vertical-align:middle;
}
.TreeMenu .s_1
{
cursor:pointer;
vertical-align:middle;
padding-left:5px;
}
.TreeMenu ul
{
padding:0;
}
.TreeMenu li
{
list-style:none;
padding:0;
}
.Closed ul
{
display:none;
}
.Child img.s
{
background:none;
cursor:default;
}
.TreeMenu ul
{
margin:0 0 0 8px;
}
.TreeMenu img.s
{
width:34px;
height:18px;
}
.TreeMenu .Opened img.s
{
background:url(../images/skin3/opened.gif) no-repeat 0 1px;
}
.TreeMenu .Closed img.s
{
background:url(../images/skin3/closed.gif) no-repeat 0 1px;
}
.TreeMenu .Child img.s
{
background:url(../images/skin3/child.gif) no-repeat 15px;
}
.divClose{ background-color:#fff;height:21px; text-align:right; border:#006600 solid 1px; border-bottom:#006600 none 1px; background-color:#ECF6E9;}
#RightCate{ height:350px; border:#006600 solid 1px; margin-left:10px;}
.allopStyle{ background-color:#fafafa; border-top:#e1e1e1 solid 1px;border-left:#e1e1e1 solid 1px;border-right:#e1e1e1 solid 1px;width:99%;
padding:2px; margin-top:5px; margin-left:2px; text-align:left;line-height:23px;
}
.pageStyle{ background-color:#fafafa; border:#e1e1e1 solid 1px;width:98%; padding:2px; margin-left:2px; text-align:center;}
.divFile { margin:2px 2px 2px 2px; height:138px; width:120px; border: #e1e1e1 solid 1px; float:left; position:relative; overflow:hidden;}
.divImage { margin:2px 2px 2px 2px; height:100px; width:116px; border: #000 solid 1px;}
.divImage img { cursor:hand; width:134px; height:100px;}
.divPage { border: #e1e1e1 solid 1px; margin:10px 10px 10px 10px; }
.divPage span {padding: 4px 4px 4px 4px;}
.divPage span a{}
.on a{ color:#f00; }
.CheckedTab { background-image:url(../images/partyCurrent.gif); width:105px; height:28px; cursor:hand; text-align:center; font-size:small; border: 1px solid #e1e1e1;}
.NoCheckTab { width:105px; height:28px; cursor:hand; text-align:center; font-size:small; border: 1px solid #e1e1e1;}
.divCheckItem{float:left; width:119px; height:104px; border:#C8D3C4 3px solid; position:relative;}
.divCheckImg{width:119px; height:104px;}
.divRemove{display:none; position:absolute; top:3px; right:3px;}
.divAdd{display:none; position:absolute; top:3px; right:3px;}
相關(guān)文章
JavaScript常見(jiàn)事件處理程序?qū)嵗偨Y(jié)
這篇文章主要介紹了JavaScript常見(jiàn)事件處理程序,結(jié)合實(shí)例形式總結(jié)分析了javascript HTML事件、DOM事件、IE事件等相關(guān)處理程序與操作技巧,需要的朋友可以參考下2019-01-01
小程序?qū)崿F(xiàn)頁(yè)面跳轉(zhuǎn)與數(shù)據(jù)傳遞方案
在開(kāi)發(fā)過(guò)程中經(jīng)常會(huì)遇到在微信小程序的頁(yè)面跳轉(zhuǎn)以及數(shù)據(jù)傳遞的知識(shí)點(diǎn),所以下面這篇文章主要給大家介紹了關(guān)于小程序?qū)崿F(xiàn)頁(yè)面跳轉(zhuǎn)與數(shù)據(jù)傳遞的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格的方法詳解
這篇文章主要為大家介紹了JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-01-01
Mozilla 表達(dá)式 __noSuchMethod__
這是一個(gè)很特殊的方法,但是其存在的意義很大。不過(guò)很可惜只有firefox支持了。一個(gè)簡(jiǎn)單的例子解釋一下它的用處2009-04-04
JS實(shí)現(xiàn)判斷圖片是否加載完成的方法分析
這篇文章主要介紹了JS實(shí)現(xiàn)判斷圖片是否加載完成的方法,結(jié)合實(shí)例形式分析了javascript常見(jiàn)的圖片加載完成判斷方法與相關(guān)操作技巧,需要的朋友可以參考下2018-07-07
JS數(shù)組方法concat()用法實(shí)例分析
這篇文章主要介紹了JS數(shù)組方法concat()用法,結(jié)合實(shí)例形式分析了JS數(shù)組concat()方法具體功能、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-01-01
javascript實(shí)現(xiàn)頁(yè)面滾屏效果
本文主要介紹了javascript實(shí)現(xiàn)頁(yè)面滾屏效果的方法,具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01

