首页 > 代码库 > ajax实现局部刷新
ajax实现局部刷新
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>demo</title>
</head>
<body>
<div class="maxBox">
<span class="T-active indexA">首页</span>
<span class="T-active indexB">九块九包邮</span>
<span class="T-active indexC">优品购</span>
</div>
<div class="content">
<img src="http://www.mamicode.com/img/1.png">
</div>
<div><img src="http://www.mamicode.com/img/foot.png"></div>
</body>
<script src="http://cdn.bootcss.com/jquery/3.0.0-alpha1/jquery.js"></script>
<script>
$(‘.T-active‘).each(function(){
$(this).click(function(){
if($(this).hasClass(‘indexA‘)){
var url = ‘./index1.html‘;
Public(url);
}else if($(this).hasClass(‘indexB‘)){
var url = ‘./index2.html‘;
Public(url);
}else if($(this).hasClass(‘indexC‘)){
var url = ‘./index3.html‘;
Public(url);
}
})
});
// $(‘.maxBox‘).on(‘click‘,‘.T-active‘,function(){
// if($(this).hasClass(‘indexA‘)){
// var url = ‘./index1.html‘;
// Public(url);
// }else if($(this).hasClass(‘indexB‘)){
// var url = ‘./index2.html‘;
// Public(url);
// }else if($(this).hasClass(‘indexC‘)){
// var url = ‘./index3.html‘;
// Public(url);
// }
//
// });
function Public(url){
$.ajax({
type:‘post‘,
cache:‘false‘,
url:url,
dataType:‘html‘,
success : function(data){
$(".content").html(data)
}
})
}
</script>
</html>
ajax实现局部刷新