Shakespeare'sPlays

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

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

    系統 1873 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');
    
    });
      

    ?

    現在我們在樣式表中添加一個影響所有表的行的樣式,然后使用alt類影響所有的偶數行:
          tr {
    
    background-color: #fff;
    
    }
    
    .alt {
    
    background-color: #ccc; 
    
    }
        
    最后,我們寫下一個jquery代碼,綁定這個類到表的所有的偶數行(<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給所有的偶數行?因為,正如:eq()選擇器一樣,:even :odd使用了js原生的零基礎的數字,因此,第一行數出來是0(偶數),第二行是不是(基數)等等。記住這個,我們我們期望我們簡單的一點點代碼創造一個看起來像下面的截屏一樣的表格:
    (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()選擇器,這個選擇器依靠父元素計算元素的位置,而不是所有被選擇的元素。這個選擇器使用或者數字,odd,even作為他的參數。
          $(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開始計數的jquery選擇器。為了像我們上面做的那樣接觸到相同的被裝飾的行——排除第二個表格中出現的那種行為——我們需要使用odd而不是even作為參數。在使用這個選擇器后,兩個表都被很好的加上了條紋,正如在下面的截屏中顯示的那樣。
    (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)
    現在我們可以看到我們漂亮的加了條紋的表格,其中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可以實現給表加上條紋和文字高亮的目的——或者是任何瀏覽器端的編程。但是,使用jquery和css,是實現這種類型的修飾的特別好的選擇,尤其是在內容是動態添加的而且我們不能接觸到html或者服務器端代碼的情況下。

    ?

    ?


    ?

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


    更多文章、技術交流、商務合作、聯系博主

    微信掃碼或搜索:z360901061

    微信掃一掃加我為好友

    QQ號聯系: 360901061

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

    【本文對您有幫助就好】

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

    發表我的評論
    最新評論 總共0條評論
    主站蜘蛛池模板: 欧美一区二区免费 | 亚洲成av| 亚洲国产中文字幕 | 日韩一区免费在线观看 | 日本捏胸摸下面免费视频 | 日本视频在线免费 | 黄色片免费在线 | 午夜小视频网站 | 日韩国产欧美视频 | 久久九九国产精品怡红院 | 台湾一级毛片永久免费 | av一区二区三区 | 欧日韩视频 | 日日干夜夜拍 | 五月婷婷天堂 | 成人二区| 久久久国产精品 | 国产精彩视频在线 | 精品国产一区二区三区免费 | 国产三级做爰在线观看∵ | 中文字幕在线综合 | 超91在线 | 国产精品色综合 | 一区二区三区四区视频 | 激情丁香开心久久综合 | 无遮挡又黄又爽又色的动态图1000 | 欧美日韩国产网站 | 欧美精品第三页 | 中文字幕精品一区久久久久 | 亚洲成人午夜在线 | 国产99久久精品一区二区 | 91懂色 | 五月婷婷欧美 | 天天碰人人 | 三级黄色片网站 | 日韩天天干| 日韩城人网站 | 精品久久久久一区二区三区 | 人人澡人人爱 | 欧洲成人午夜免费大片 | 色多多视频导航 |