欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

AJAX相關(guān)

當(dāng)前位置:主頁(yè) > 網(wǎng)絡(luò)編程 > AJAX相關(guān) >

ajax實(shí)現(xiàn)頁(yè)面的局部加載

來源:本站原創(chuàng)|時(shí)間:2020-01-11|欄目:AJAX相關(guān)|點(diǎn)擊: 次

ajax如何實(shí)現(xiàn)頁(yè)面的局部加載,具體如下

點(diǎn)擊頭部即右上角的鏈接時(shí),頁(yè)面會(huì)根據(jù)相應(yīng)的鏈接加載新的內(nèi)容,顯示在下方;在中間區(qū)域有3欄,當(dāng)點(diǎn)擊1欄中的鏈接,2欄中會(huì)顯現(xiàn)相應(yīng)的內(nèi)容,點(diǎn)擊2欄中的內(nèi)容,3欄中的內(nèi)容又會(huì)根據(jù)2欄的鏈接來加載顯示內(nèi)容。

頁(yè)面效果如下:

js代碼如下:

$("header a").on("click",function(e){
 e.preventDefault(); //阻止事件默認(rèn)行為
 var href = this.href; //記錄要加載頁(yè)面的鏈接

 //更新當(dāng)前連接狀態(tài)
 $("header a").removeClass("current");
 $(this).addClass("current");

 var $content = $("#content");
 var $container = $("#container");
 $container.remove();
 $content.load(href + " #container"); //加載頁(yè)面id = container的內(nèi)容

 });


 var times; //times用來存儲(chǔ)所有活動(dòng)的環(huán)節(jié)時(shí)間表
 $.ajax({
 type:"get", //指定get方式
 url:"example.json",
 async:true,
 beforeSend: function(jqXHR){ 
  //在瀏覽器請(qǐng)求JSON數(shù)據(jù)之前,腳本會(huì)檢查瀏覽器是否支持overrideMineType()方法。
  //該方法會(huì)用來告知服務(wù)器應(yīng)當(dāng)返回JSON數(shù)據(jù)。
  //當(dāng)服務(wù)器意外配置成返回其他格式的數(shù)據(jù)時(shí),就可以使用這個(gè)方法了
  if(jqXHR.overrideMimeType){
  jqXHR.overrideMimeType("application/json"); 
  }
 }
 });

 function loadTimeTable(){//加載example.json文件中加載時(shí)間表的數(shù)據(jù)
 $.getJSON(
  "example.json"
 ).done(function(data){ //加載成功,值被保存到times中
  //console.log(data);
  times = data;
 }).fail(function(){ //加載失敗
  $("#event").html("Sorry!we could not load the timetable at the moment");
 });
 }

 loadTimeTable(); //調(diào)用函數(shù)

 //點(diǎn)擊活動(dòng)名稱,將該活動(dòng)的時(shí)間加載到中欄
 $("#content").on("click","#event a",function(e){
 e.preventDefault(); 

 var loc = this.id.toUpperCase(); //保存活動(dòng)位置的名稱
 var newContent = ''; //設(shè)置展示樣式排版
 for(var i = 0; i < times[loc].length; i++){
  //alert(times[loc][i].time);
  newContent += '<li><span class="time">' +times[loc][i].time +'</span>';
  newContent += '<a href="descriptions.html#" rel="external nofollow" title="' +times[loc][i].title.replace(/ /g,'-')+ '">';
  newContent += times[loc][i].title + '</a></li>';
 }

 $("#sessions").html('<ul>'+newContent+'</ul>');

 $("#event a").removeClass("current"); //更新活動(dòng)鏈接的class屬性,借此凸顯當(dāng)前活動(dòng)
 $(this).addClass("current");

 $("#details").text(''); //如果第三欄中包含內(nèi)容,就清空它
 });


 //點(diǎn)擊中欄中的環(huán)節(jié)是產(chǎn)生相應(yīng),它會(huì)加載環(huán)節(jié)的描述信息
 $("#content").on("click","#sessions a",function(e){
 e.preventDefault();
 var fragment = this.href.replace('#',' #');
 //更新當(dāng)前連接狀態(tài)
 $("#details a").removeClass("current");
 $(this).addClass("current");

 $("#details").load(fragment+this.title); //查找到descriptions.html頁(yè)面中id對(duì)應(yīng)的部分加載到當(dāng)前頁(yè)面
 });

整個(gè)demo的地址

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有