第一个html页面的js代码:
$.ajax({
url:"/xinyuncan/json_home/data.json", //读取的是项目中测试用的json文件
type:"GET",
dataType:"json",
success:function(data){
console.log("连接成功"+data);
showData(data);
},
error:function(e){
console.log("连接失败"+e);
}
})
function showData(data){
console.log(data.mTitle);
console.log($(".dt h3"));
$(".dt .new_box4").each(function(index){
$(this).click(function(){
location.href = "page2hydt.html?" + "index=" + encodeURI(index);
})
$(this).find("h3").html(data.hydt[index].mTitle);
$(this).find("p").html(data.hydt[index].desPart.one);
$(this).find("span").html("新闻快讯/"+data.hydt[index].time);
})
$(".xw .new_box4").each(function(index){
$(this).click(function(){
location.href = "page2gsxw.html?" + "index=" + encodeURI(index); //此处为url传递参数的方法,将当前div下标传过去,让第二个html页面读取指定下标的json数据
})
$(this).find("h3").html(data.gsxw[index].mTitle);
$(this).find("p").html(data.gsxw[index].desPart.one);
$(this).find("span").