最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用js將ajax獲取到的后臺(tái)數(shù)據(jù)動(dòng)態(tài)加載至網(wǎng)頁(yè)中的方法

 更新時(shí)間:2018年08月08日 08:46:13   作者:sning999  
今天小編就為大家分享一篇利用js將ajax獲取到的后臺(tái)數(shù)據(jù)動(dòng)態(tài)加載至網(wǎng)頁(yè)中的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧

動(dòng)態(tài)生成二級(jí)菜單樹:

<script>
jQuery(function($) {
/**********
獲取未處理報(bào)警信息總數(shù)
**************/
var result;
$.ajax({
async:false,
cache:false,
url: "alarm_findPageAlarm.do",//訪問后臺(tái)接口取數(shù)據(jù)
// dataType : "json",
type: 'POST',
success: function(data){
result = eval('('+ data +')');
}
});
var alarmCount;
alarmCount = result.total;

/**********

靜態(tài)代碼形式

**********/
/* 
<li>
<a href="#" rel="external nofollow" class="dropdown-toggle">
<i class="icon-desktop"></i>
<span class="menu-text"> 設(shè)備管理 </span>


<b class="arrow icon-angle-down"></b>
</a>


<ul class="submenu">
<li>
<a href="smartTerminal.html" rel="external nofollow" >
<i class="icon-double-angle-right"></i>
智能終端管理
</a>
</li>
<li>
<a href="labelPrinter.html" rel="external nofollow" >
<i class="icon-double-angle-right"></i>
標(biāo)簽打印機(jī)管理
</a>
</li>
</ul>
</li>
*/

/*****從后臺(tái)取出導(dǎo)航欄數(shù)據(jù)******/
$.ajax({
async:true,
cache:false,
url: "user_getMenuBuf.do",
// dataType : "json",
type: 'POST',
success: function(result){
var result = eval('('+ result +')');
if(result != undefined && result.length > 0){
var firstMenu = [];
var firstHref = [];
var firstIcon = [];
var subMenu = [];

/******一級(jí)導(dǎo)航欄數(shù)據(jù)*******/
for (var i = 0; i < result.length; i++){
firstMenu[i] = result[i].name;
firstHref[i] = result[i].url;
firstIcon[i] = result[i].iconCls;

/*******添加li標(biāo)簽********/
var menuInfo = document.getElementById("menuInfo");
var firstLi = document.createElement("li");//創(chuàng)建新的 li元素
menuInfo.appendChild(firstLi);//將此li元素添加至頁(yè)面的ul下一級(jí)中
firstLi.style.borderBottom = "0px solid #CCEBF8";//設(shè)置li下邊框樣式

/******設(shè)置選中l(wèi)i、離開li時(shí)li的樣式********/
firstLi.onmouseover = function(){
this.style.background = "#23ACFA";
};
/* firstLi.onmouseover = function(){
this.style.background = "#23ACFA";
}; */
firstLi.onmouseout=function(){
this.style.background = "#0477C0";
};

/******添加a標(biāo)簽**********/
var firstALabel = document.createElement("a");
firstALabel.setAttribute("href", firstHref[i]);//js為新添加的a元素動(dòng)態(tài)設(shè)置href屬性
firstALabel.setAttribute("class", "dropdown-toggle");
//firstALabel.className = "dropdown-toggle";//兼容性好
firstALabel.setAttribute("target", "content");
//firstALabel.style.backgroundImage="url(./img/17.jpg)"
firstALabel.style.background = "#0477C0";//js為新添加的a元素動(dòng)態(tài)設(shè)置背景顏色
// background:url(./img/17.jpg);
firstALabel.style.marginLeft = "20px";//js為新添加的a元素動(dòng)態(tài)設(shè)置左外邊距
firstLi.appendChild(firstALabel);
firstALabel.onmouseover = function(){
this.style.background = "#23ACFA";
};
/* firstALabel.onmouseover = function(){
this.style.background = "#23ACFA";
}; */
firstALabel.onmouseout=function(){
this.style.background = "#0477C0";
};


/*******添加i標(biāo)簽*******/
var firstILavel = document.createElement("i");
firstILavel.setAttribute("class", firstIcon[i]);
firstILavel.style.color = "#F4F8FF";//動(dòng)態(tài)設(shè)置i元素的顏色
firstALabel.appendChild(firstILavel);

/*********添加span標(biāo)簽**********/
var firstSpan = document.createElement("span");
firstSpan.className = "menu-text";
firstSpan.innerHTML = firstMenu[i];//js為新添加的span元素動(dòng)態(tài)設(shè)置顯示內(nèi)容
firstSpan.style.fontSize = "14.5px";//js為新添加的span元素動(dòng)態(tài)設(shè)置顯示內(nèi)容的字體大小
firstSpan.style.color = "#66D2F1";//js為新添加的span元素動(dòng)態(tài)設(shè)置顯示內(nèi)容的字體顏色
firstSpan.style.marginLeft = "15px";
firstALabel.appendChild(firstSpan);

if (firstMenu[i] == "報(bào)警信息管理"){
var alarmIcon = document.createElement("span");
alarmIcon.className = "badge badge-important";
alarmIcon.innerHTML = alarmCount; //alarmCount為全局變量,且是通過ajax從后臺(tái)獲取到的
firstSpan.appendChild(alarmIcon);
}

if (result[i].children.length > 0){
var secondHref = [];
var secondMenu = [];
var secondIcon = [];

/*******添加b標(biāo)簽********/
var firstBLabel = document.createElement("b");
firstBLabel.className = "arrow icon-angle-down";
firstBLabel.style.color = "white";
firstALabel.appendChild(firstBLabel);

/********添加ul標(biāo)簽************/
var secondUl = document.createElement("ul");
secondUl.setAttribute("class", "submenu");
firstLi.appendChild(secondUl);

for (var j = 0; j < result[i].children.length; j++){
secondHref[j] = result[i].children[j].url;
secondMenu[j] = result[i].children[j].name;
secondIcon[j] = result[i].children[j].iconCls;

/******添加li標(biāo)簽*******/
var secondLi = document.createElement("li");
secondLi.style.background = "#CCEBF8";
secondUl.appendChild(secondLi);

/*******添加a標(biāo)簽*******/
var secondALabel = document.createElement("a");
secondALabel.setAttribute("href", secondHref[j]);
secondALabel.setAttribute("target", "content");
//secondALabel.style.background = "#CCEBF8";
secondLi.appendChild(secondALabel);

/*******添加i標(biāo)簽**********/
var secondILabel = document.createElement("i");
secondILabel.setAttribute("class", "icon-double-angle-right");
secondALabel.appendChild(secondILabel);

/******添加二級(jí)導(dǎo)航信息********/
secondALabel.innerHTML = secondMenu[j];
secondALabel.style.fontSize = "15px";
//secondALabel.style.marginLeft = "60px";
}
}
}
   }
  }, 
 error: function() { 
 alert("加載菜單失敗"); 
 } 
});
})
</script>

靜態(tài)生成菜單樹的代碼:

生成菜單樹的效果:

以上這篇利用js將ajax獲取到的后臺(tái)數(shù)據(jù)動(dòng)態(tài)加載至網(wǎng)頁(yè)中的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript調(diào)用模式與this關(guān)鍵字綁定的關(guān)系

    JavaScript調(diào)用模式與this關(guān)鍵字綁定的關(guān)系

    這篇文章主要介紹了JavaScript調(diào)用模式與this關(guān)鍵字綁定的關(guān)系 的相關(guān)資料,需要的朋友可以參考下
    2018-04-04
  • javascript類數(shù)組的深入理解

    javascript類數(shù)組的深入理解

    這篇文章主要給大家介紹了關(guān)于javascript類數(shù)組的深入理解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 詳解javascript中對(duì)數(shù)據(jù)格式化的思考

    詳解javascript中對(duì)數(shù)據(jù)格式化的思考

    本篇文章主要介紹了詳解javascript中對(duì)數(shù)據(jù)文本格式化的思考 ,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01
  • JavaScript遍歷對(duì)象的七種方法匯總

    JavaScript遍歷對(duì)象的七種方法匯總

    這篇文章主要介紹了JavaScript遍歷對(duì)象的七種方法匯總,文章通過從屬性可枚舉性問題與遍歷方法兩個(gè)大方面講述全文,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-08-08
  • 微信小程序日期時(shí)間選擇器使用方法

    微信小程序日期時(shí)間選擇器使用方法

    這篇文章主要為大家詳細(xì)介紹了微信小程序日期時(shí)間選擇器的使用方法,自定義精確到分秒或時(shí)段,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • uni-app中如何使用uni.showModal添加輸入框

    uni-app中如何使用uni.showModal添加輸入框

    uni-app是一種使用Vue.js開發(fā)所有前端應(yīng)用的框架,uni.showModal是其API之一,用于展示模態(tài)彈窗并可添加輸入框,通過editable屬性設(shè)置彈窗內(nèi)容是否可編輯,通過success回調(diào)函數(shù)處理用戶點(diǎn)擊結(jié)果,這提供了一個(gè)交互式元素,方便在應(yīng)用中收集用戶輸入的信息
    2024-09-09
  • js TextArea的選中區(qū)域處理

    js TextArea的選中區(qū)域處理

    js中對(duì)于TextArea的選中區(qū)域后進(jìn)行處理的代碼,需要的朋友可以參考下。
    2010-12-12
  • JS根據(jù)key值獲取URL中的參數(shù)值及把URL的參數(shù)轉(zhuǎn)換成json對(duì)象

    JS根據(jù)key值獲取URL中的參數(shù)值及把URL的參數(shù)轉(zhuǎn)換成json對(duì)象

    本篇文章主要圍繞js url 參數(shù)值展開話題,js根據(jù)key值獲取url中的參數(shù)值,接著把url的參數(shù)轉(zhuǎn)換成json,感興趣的朋友一起來(lái)學(xué)習(xí)吧,本文寫的不好地方還望多多指出批評(píng)建議
    2015-08-08
  • 微信小程序中吸底按鈕適配iPhone X方案

    微信小程序中吸底按鈕適配iPhone X方案

    這篇文章主要介紹了微信小程序中吸底按鈕適配iPhone X方案,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-11-11
  • 原生js實(shí)現(xiàn)波浪導(dǎo)航效果

    原生js實(shí)現(xiàn)波浪導(dǎo)航效果

    這篇文章主要為大家詳細(xì)介紹了原生js實(shí)現(xiàn)波浪導(dǎo)航效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評(píng)論

衡东县| 太和县| 元氏县| 罗定市| 阿瓦提县| 琼海市| 古田县| 丹寨县| 调兵山市| 新干县| 封丘县| 库伦旗| 马山县| 崇州市| 北流市| 无极县| 宁安市| 平和县| 喀喇沁旗| 得荣县| 惠州市| 徐闻县| 当阳市| 眉山市| 广元市| 西昌市| 德江县| 乐至县| 固始县| 自贡市| 义马市| 金塔县| 措勤县| 广德县| 布尔津县| 富顺县| 仁化县| 静安区| 康马县| 南平市| 天全县|