Shakespeare'sPlays

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

      AsYouLikeItComedy
      <label id="fk1uf"></label>
    1. <pre id="fk1uf"></pre>

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

      系統(tǒng) 2041 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,讓我們看一下我們?nèi)绾问褂檬褂盟麄冎粊頌榛A(chǔ)的表格加樣式,見如下的表格:(同上的代碼)

      ?

      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)

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

      (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>標(biāo)簽)
            $(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ù)行?因?yàn)?,正?eq()選擇器一樣,:even :odd使用了js原生的零基礎(chǔ)的數(shù)字,因此,第一行數(shù)出來是0(偶數(shù)),第二行是不是(基數(shù))等等。記住這個,我們我們期望我們簡單的一點(diǎn)點(diǎn)代碼創(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');
      
      });
          
      注意在第二個表格中,這個結(jié)果可能不是我們想要的,正如在這個Plays表格中,最后一行有著這個"交替"的灰色背景,在Sonnets表格中,第一行有個這個簡單的白色的背景。避免這種問題的一個方法是使用:nth-child()選擇器,這個選擇器依靠父元素計(jì)算元素的位置,而不是所有被選擇的元素。這個選擇器使用或者數(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開始計(jì)數(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');
      
      });
          
      在最后一個接觸定制選擇器,我們假設(shè)由于一些原因,我們想要高亮所有的涉及到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展示了顯著的特點(diǎn):
      (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.
      有一點(diǎn)特別需要說明的是:contains()選擇器是大小寫敏感的,使用$("td:contains(henry)"),而不是使用大寫的H,將不會選擇任何元素。
      誠然,我們有很多方法在不使用jquery可以實(shí)現(xiàn)給表加上條紋和文字高亮的目的——或者是任何瀏覽器端的編程。但是,使用jquery和css,是實(shí)現(xiàn)這種類型的修飾的特別好的選擇,尤其是在內(nèi)容是動態(tài)添加的而且我們不能接觸到html或者服務(wù)器端代碼的情況下。

      ?

      ?


      ?

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


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

      微信掃碼或搜索:z360901061

      微信掃一掃加我為好友

      QQ號聯(lián)系: 360901061

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

      【本文對您有幫助就好】

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

      發(fā)表我的評論
      最新評論 總共0條評論
      主站蜘蛛池模板: 国产在线精品一区二区三区不卡 | 免费看黄片毛片 | 亚洲精品第一区二区在线 | 成人亚洲综合 | 91资源在线视频 | 亚洲不卡 | 国产精品a区 | 欧美在线精品一区二区三区 | 超碰在线小说 | 五月婷婷六月综合 | 97在线观看免费视频 | 99久久www免费| 久久精品国产精品2020 | 亚洲精品线在线观看 | 伊人中文字幕 | 五月天色中色 | 热灸灸这里只有精品 | 四虎永久在线精品国产馆v视影院 | 国产精品久久免费观看 | 手机看片福利在线 | 亚洲国产第一区二区三区 | 伊人第一页 | 久久精品国产线看观看亚洲 | 中文国产成人久久精品小说 | 精品在线视频播放 | 一本大道久久a久久综合 | 一级啪啪片 | 波多野结衣乳巨码无在线观看 | 久久久久久全国免费观看 | 日韩成| 中国一级特黄高清免费的大片 | 亚洲精品日本一区二区在线 | 国产综合成人久久大片91 | 国内精自线一二区 | 91热久久免费频精品黑人99 | 免费四虎永久在线精品 | 成人午夜视频在线播放 | 一级特黄a免费大片 | 国内精品久久久久久影院老狼 | 免费毛片观看 | 四房激情网 |