JQuery學習——標籤頁效果二

來源:互聯網
上載者:User

 我們最終實現的效果:當單擊標籤一的時候,下面載入的是一個html的全部內容;當單擊標籤二的時候,下面載入的是一個asp.net頁面的一部分內容,標籤三未添加效果。 頁面前台的代碼[html] <%@ Page Language="C#" AutoEventWireup="true" CodeFile="tab.aspx.cs" Inherits="tab" %>    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head runat="server">      <title></title>      <link href="css/tab.css" rel="stylesheet" type="text/css" />      <script src="js/jquery.js" type="text/javascript"></script>      <script src="js/tab.js" type="text/javascript"></script>  </head>  <body>      <form id="form1" runat="server">      <div id="firstDiv">          <ul>              <li class="tabin">標籤一</li>              <li>標籤二</li>              <li>標籤三</li>          </ul>          <div class="contentin">              我是標籤一的內容</div>          <div>              我是標籤二的內容</div>          <div>              我是標籤三的內容</div>      </div>      <br />      <br />      <br />      <div id="secondDiv">          <ul>              <li class="tabin">標籤一</li>              <li>標籤二</li>              <li>標籤三</li>          </ul>          <div id="secondContentin">              <img alt="裝載中" src="images/img-loading.gif" />              <div id="realContentin"></div>          </div>      </div>      </form>  </body>  </html>   tab.css[css]  ul,li  {      list-style:none;      margin:0;      padding:0;      }  #firstDiv li  {      background-color:#6E6E6E;      float:left;      color:White;      padding:5px;      margin-right:3px;       border: 1px solid white;         }  #firstDiv .tabin  {      border:1px solid #6E6E6E;      }  #firstDiv div  {      clear:left;      background-color:#6E6E6E;      width:200px;      height:100px;      display:none;      }  #firstDiv .contentin  {      display:block;      }           #secondDiv li  {      float:left;      color:Blue;      background-color:White;      padding:5px;      margin-right:3px;      /*當滑鼠放在標籤上時,顯示成小手*/      cursor:pointer;      }  #secondDiv li.tabin  {      background-color:#F2F6F8;      border:1px solid black;      border-bottom:0;      /*只有position設定成relative或者absolute的時候z-index才有效*/      position:relative;      z-index:100;      }  #secondContentin  {      width:300px;      height:200px;      padding:10px;      background-color:#F2F6F8;      clear:left;      border:1px solid black;      /*下面是讓底下的內容向上移動一個像素     *但是,我們可以看到,並沒有達到我們想要的效果,接下     *來要上上面的li顯示層次在最上面,這樣就蓋住了下面的div的border     */      position:relative;      top:-1px;      }  /*開始的時候讓loading圖片隱藏*/  img  {      display:none;      }   關於z-index的問題,注釋上有說明,下面的是我截的js手冊上的內容:tab.js[javascript] /// <reference path="jquery.js" />    $(document).ready(function () {        var setTimeouId;        $("#firstDiv li").each(function (index) {          $(this).mouseover(function () {              var nodeTabin = $(this);              setTimeouId = setTimeout(function () {                  $("#firstDiv .contentin").removeClass("contentin");                  $("#firstDiv .tabin").removeClass("tabin");                    $("#firstDiv div").eq(index).addClass("contentin");                  //我在這裡犯錯了哦,不應該再用this  this如果用在這裡的話那麼是指的window                  nodeTabin.addClass("tabin");              }, 300);          }).mouseout(function () {              clearTimeout(setTimeouId);          });      });        $("#realContentin").load("HTMLPage.htm");      $("#secondDiv li").each(function (index) {          $(this).click(function () {              /*更改樣式*/              $("#secondDiv li.tabin").removeClass("tabin");              $(this).addClass("tabin");                if (index == 0) {                  $("#realContentin").load("HTMLPage.htm");              } else if (index == 1) {                  $("#realContentin").load("Default.aspx div");              } else if (index == 2) {                }          });      });        //我剛開始的時候用的是jquery的最新版本,但是出現了無法綁定的問題。      $("#secondContentin img").bind("ajaxStart", function () {          $(this).show();      }).bind("ajaxStop", function () {          //setTimeout(function(){$(this).hide()},300);          $(this).hide(1000);      });  });              

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.