jquery的ajax后台后去数据的table切换

来源:互联网 发布:qt 调用dotnet 编程 编辑:程序博客网 时间:2024/05/29 07:03
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">

*{
margin: 0;
padding: 0;
}
span{
display: inline-block;
width: 100px;
height: 50px;
background-color: gray;
border: 1px solid red;
text-align: center;
line-height: 50px;
}
     .main{
      width: 410px;
      height: 400px;
      /*background-color: red;*/
      position: relative;
     }
     .main img{
      width: 410px;
      height: 400px
     }
     .main p{
      width: 410px;
      height: 50px;
      background-color: black;
      opacity: 0.5;
      text-align: center;
      font-size: 20px;
      line-height: 50px;
      position: absolute;
bottom: 0;
color: white;
     }
     .img_div{
      display: none;
     }
</style>
</style>
</head>
<body>
<div class="show">
  <div class="btn">
  <span>第一块</span><span>第二块</span><span>第三块</span><span>第四块</span>
  </div>
    <div class="main">
   
    </div>
  </div>


</body>
<script  src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
 //后台获取数据
  $.ajax({
  url:'http://localhost/AJAX/php/img.php',
  type:'post',
  data:{type:''},
  success:function(res){
 
            console.log(res);
            var arr= JSON.parse(res);
           console.log(arr);
             //创建节点加载图片
             for(var i=0;i<arr.length;i++){
           var myDiv=$('<div class="img_div"></div>');
               myDiv.html('<img src="'+arr[i].url+'"><p>'+arr[i].title+'<p>');
             $('.main').append(myDiv);
            
              }
               $('.img_div').eq(0).css({'display':'block'});
  },
  async:true
  });
   /*..................table切换.........................*/
 
      //绑定按钮事件
      $('span').on('click',function(){
          
        $(this).css({'backgroundColor':'red'}).siblings().css({'backgroundColor':'gray'});


         $('.img_div').eq($(this).index()).css({'display':'block'}).siblings().css({'display':'none'});
      });
</script>
</html>
阅读全文
0 0
原创粉丝点击