點擊頭部即右上角的鏈接時,頁面會根據(jù)相應的鏈接加載新的內(nèi)容,顯示在下方;在中間區(qū)域有3欄,當點擊1欄中的鏈接,2欄中會顯現(xiàn)相應的內(nèi)容,點擊2欄中的內(nèi)容,3欄中的內(nèi)容又會根據(jù)2欄的鏈接來加載顯示內(nèi)容。
$("header a").on("click",function(e){
e.preventDefault(); //阻止事件默認行為
var href = this.href; //記錄要加載頁面的鏈接
//更新當前連接狀態(tài)
$("header a").removeClass("current");
$(this).addClass("current");
var $content = $("#content");
var $container = $("#container");
$container.remove();
$content.load(href + " #container"); //加載頁面id = container的內(nèi)容
});
var times; //times用來存儲所有活動的環(huán)節(jié)時間表
$.ajax({
type:"get", //指定get方式
url:"example.json",
async:true,
beforeSend: function(jqXHR){
//在瀏覽器請求JSON數(shù)據(jù)之前,腳本會檢查瀏覽器是否支持overrideMineType()方法。
//該方法會用來告知服務器應當返回JSON數(shù)據(jù)。
//當服務器意外配置成返回其他格式的數(shù)據(jù)時,就可以使用這個方法了
if(jqXHR.overrideMimeType){
jqXHR.overrideMimeType("application/json");
}
}
});
function loadTimeTable(){//加載example.json文件中加載時間表的數(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ù)
//點擊活動名稱,將該活動的時間加載到中欄
$("#content").on("click","#event a",function(e){
e.preventDefault();
var loc = this.id.toUpperCase(); //保存活動位置的名稱
var newContent = ''; //設置展示樣式排版
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"); //更新活動鏈接的class屬性,借此凸顯當前活動
$(this).addClass("current");
$("#details").text(''); //如果第三欄中包含內(nèi)容,就清空它
});
//點擊中欄中的環(huán)節(jié)是產(chǎn)生相應,它會加載環(huán)節(jié)的描述信息
$("#content").on("click","#sessions a",function(e){
e.preventDefault();
var fragment = this.href.replace('#',' #');
//更新當前連接狀態(tài)
$("#details a").removeClass("current");
$(this).addClass("current");
$("#details").load(fragment+this.title); //查找到descriptions.html頁面中id對應的部分加載到當前頁面
});