Shakespeare'sPlays

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

AsYouLikeItComedy

    1. <pre id="cxfvp"><label id="cxfvp"><th id="cxfvp"></th></label></pre>

      (3)選擇元素——(9)為交替的列加樣式(Styl

      系統(tǒng) 1821 0

      Two very useful custom selectors in the jQuery library are :oddand :even. Let's take a?look at how we can use one of them for basic table striping, given the following tables:

      ?

          <h2>Shakespeare's Plays</h2>
      
      <table>
      
      <tr>
      
      <td>As You Like It</td>
      
      <td>Comedy</td>
      
      <td></td>
      
      </tr>
      
      <tr>
      
      <td>All's Well that Ends Well</td>
      
      <td>Comedy</td>
      
      <td>1601</td>
      
      </tr>
      
      <tr>
      
      <td>Hamlet</td>
      
      <td>Tragedy</td>
      
      <td>1604</td>
      
      </tr>
      
      <tr>
      
      <td>Macbeth</td>
      
      <td>Tragedy</td>
      
      <td>1606</td>
      
      </tr>
      
      <tr>
      
      <td>Romeo and Juliet</td>
      
      <td>Tragedy</td>
      
      <td>1595</td>
      
      </tr>
      
      <tr>
      
      <td>Henry IV, Part I</td>
      
      <td>History</td>
      
      <td>1596</td>
      
      </tr>
      
      <tr>
      
      <td>Henry V</td>
      
      <td>History</td>
      
      <td>1599</td>
      
      </tr>
      
      </table>
      
      <h2>Shakespeare's Sonnets</h2>
      
      <table>
      
      <tr>
      
      <td>The Fair Youth</td>
      
      <td>1–126</td>
      
      </tr>
      
      <tr>
      
      <td>The Dark Lady</td>
      
      <td>127–152</td>
      
      </tr>
      
      <tr>
      
      <td>The Rival Poet</td>
      
      <td>78–86</td>
      
      </tr>
      
      </table>
        


      jquey中有兩個有用的選擇器,:odd,:even,讓我們看一下我們如何使用使用他們之一來為基礎的表格加樣式,見如下的表格:(同上的代碼)

      ?

      With minimal styles applied from our stylesheet, these headings and tables appear?quite plain. The table has a solid white background, with no styling separating one?row from the next:

      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)

      通過樣式表最少的樣式,這些頭部和表格顯示的相當平常,這個表格有一個固定的白色背景,兩個相鄰的行之間沒有分割樣式:

      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)

      Now we can add a style to the stylesheet for all table rows, and use an altclass for?the odd rows:

      ?

          tr {
      
      background-color: #fff;
      
      }
      
      .alt {
      
      background-color: #ccc; 
      
      }
        

      Finally, we write our jQuery code, attaching the class to the odd-numbered table?rows (<tr>tags):

      ?

      ?

          $(document).ready(function() {
      
      $('tr:even').addClass('alt');
      
      });
        

      ?

      現(xiàn)在我們在樣式表中添加一個影響所有表的行的樣式,然后使用alt類影響所有的偶數(shù)行:
            tr {
      
      background-color: #fff;
      
      }
      
      .alt {
      
      background-color: #ccc; 
      
      }
          
      最后,我們寫下一個jquery代碼,綁定這個類到表的所有的偶數(shù)行(<tr>標簽)
            $(document).ready(function() {
      
      $('tr:even').addClass('alt');
      
      });
          
      But wait! Why use the :evenselector for odd-numbered rows? Well, just as with?the :eq()selector, the :evenand :oddselectors use JavaScript's native zero-based?numbering. Therefore, the first row counts as 0 (even) and the second row counts?as 1 (odd), and so on. With this in mind, we can expect our simple bit of code to?produce tables that look similar to the following screenshot:
      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)
      但是,等一下,為什么使用:even給所有的偶數(shù)行?因為,正如:eq()選擇器一樣,:even :odd使用了js原生的零基礎的數(shù)字,因此,第一行數(shù)出來是0(偶數(shù)),第二行是不是(基數(shù))等等。記住這個,我們我們期望我們簡單的一點點代碼創(chuàng)造一個看起來像下面的截屏一樣的表格:
      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)
      Note that for the second table, this result may not be what we intend. As the last row?in the Playstable has the "alternate" gray background, the first row in the Sonnetstable has the plain white background. One way to avoid this type of problem is to?use the :nth-child()selector instead, which counts an element's position relative?to its parent element, rather than relative to all the elements selected so far. This?selector can take either a number, odd, or evenas its argument.
            $(document).ready(function() {
      
      $('tr:nth-child(odd)').addClass('alt');
      
      });
          
      注意在第二個表格中,這個結果可能不是我們想要的,正如在這個Plays表格中,最后一行有著這個"交替"的灰色背景,在Sonnets表格中,第一行有個這個簡單的白色的背景。避免這種問題的一個方法是使用:nth-child()選擇器,這個選擇器依靠父元素計算元素的位置,而不是所有被選擇的元素。這個選擇器使用或者數(shù)字,odd,even作為他的參數(shù)。
            $(document).ready(function() {
      
      $('tr:nth-child(odd)').addClass('alt');
      
      });
          
      As before, note that :nth-child()is the only jQuery selector that is one-based.?To achieve the same row striping as we did above—except with consistent?behavior for the second table—we need to use oddrather than evenas the?argument. With this selector in place, both tables are now striped nicely, as?shown in the following screenshot:
      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)
      正如之前說的,注意到:nth-child()只是從0開始計數(shù)的jquery選擇器。為了像我們上面做的那樣接觸到相同的被裝飾的行——排除第二個表格中出現(xiàn)的那種行為——我們需要使用odd而不是even作為參數(shù)。在使用這個選擇器后,兩個表都被很好的加上了條紋,正如在下面的截屏中顯示的那樣。
      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)
      For one final custom-selector touch, let's suppose for some reason we want to?highlight any table cell that referred to one of the Henryplays. All we have to?do—after adding a class to the stylesheet to make the text bold and italicized?(.highlight {font-weight: bold; font-style: italic;})—is add a line to?our jQuery code, using the :contains()selector, as shown in the following?code snippet:
            $(document).ready(function() {
      
      $('tr:nth-child(odd)').addClass('alt');
      
      $('td:contains(Henry)').addClass('highlight');
      
      });
          
      在最后一個接觸定制選擇器,我們假設由于一些原因,我們想要高亮所有的涉及到Henry展示出來的的表格。我們需要做的是——在添加一個可以使文字加粗和斜體的類到樣式表(.highlight {font-weight: bold; font-style: italic;})中以后——在我們的jquery代碼中添加一行代碼,使用:contains()選擇器,正如下面的代碼片段顯示的那樣。
            $(document).ready(function() {
      
      $('tr:nth-child(odd)').addClass('alt');
      
      $('td:contains(Henry)').addClass('highlight');
      
      });
          
      So, now we can see our lovely striped table with the Henryplays prominently?featured:
      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)
      現(xiàn)在我們可以看到我們漂亮的加了條紋的表格,其中Henry展示了顯著的特點:
      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)
      It's important to note that the :contains()selector is case-sensitive. Using?$('td:contains(henry)')instead, without the uppercase "H," would select?no cells.
      Admittedly, there are ways to achieve the row striping and text highlighting?without jQuery—or any client-side programming, for that matter. Nevertheless,?jQuery, along with CSS, is a great alternative for this type of styling in cases where?the content is generated dynamically and we don't have access to either the HTML?or server-side code.
      有一點特別需要說明的是:contains()選擇器是大小寫敏感的,使用$("td:contains(henry)"),而不是使用大寫的H,將不會選擇任何元素。
      誠然,我們有很多方法在不使用jquery可以實現(xiàn)給表加上條紋和文字高亮的目的——或者是任何瀏覽器端的編程。但是,使用jquery和css,是實現(xiàn)這種類型的修飾的特別好的選擇,尤其是在內容是動態(tài)添加的而且我們不能接觸到html或者服務器端代碼的情況下。

      ?

      ?


      ?

      (3)選擇元素——(9)為交替的列加樣式(Styling alternate rows)


      更多文章、技術交流、商務合作、聯(lián)系博主

      微信掃碼或搜索:z360901061

      微信掃一掃加我為好友

      QQ號聯(lián)系: 360901061

      您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

      【本文對您有幫助就好】

      您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

      發(fā)表我的評論
      最新評論 總共0條評論
      主站蜘蛛池模板: 青青热久免费精品视频在线观看 | 特黄特色一级aa毛片免费观看 | 欧美开嫩苞实拍视频在线观看 | 久久久久久久网 | 四虎在线免费观看 | 中文字幕一区二区三区免费视频 | 国产精品66| 欧美日韩一本大道香蕉欧美 | 青青草国产免费一区二区 | 国产一级毛片国产 | 亚洲h在线观看 | 欧美一级爱爱视频 | 国产日韩欧美亚洲综合首页 | 国产欧美精品国产国产专区 | 91精品免费久久久久久久久 | 天天干夜啪 | 免费看一级a一片毛片 | 成 人 a v免费视频 | 久久久久久久国产精品 | 久久99精品国产99久久6男男 | 亚洲国产精品aa在线看 | 国产精品一区二区四区 | 国产对白有声小说 | 久久精品综合视频 | 免费精品一区二区三区在线观看 | 精品国产品欧美日产在线 | 亚洲午夜片子大全精品 | 久久亚洲这里只有精品18 | 免费一级毛片在线播放视频 | 精品久久国产老人久久综合 | 人人揉揉香蕉大免费不卡 | 亚洲第一a| 久久精品加勒比中文字幕 | 亚洲五月综合缴情婷婷 | 久国产精品视频 | 亚洲国产成人久久综合一区77 | 天天操综合视频 | 四虎影院在线观看网站 | 日本午夜www高清视频 | 国产夜色 | 中文字幕欧美日韩 |