學習JQuery - 3

來源:互聯網
上載者:User

2. 屬性選取器

上一節實現的效果用圖片



我們現在需要在email, Hamlet, Herry V增加連結表徵圖和背景色。<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ICAgINT1w7TU2s2s0fnKx6GwYaGxserHqbXE0aHU8cb3yc+9+NDQx/i31sTYo788L3A+CjxwPiAgICDV4r7Nysexvr3a0qq9srXExNrI3aGjPC9wPgo8cD4gICAgse3P1tDOyr2jujwvcD4KPHA+ICAgIENTU9Gh1PHG96OoVGFnLCBJRCwgQ2xhc3OjqS7K9NDUPC9wPgo8cD4gICAgPC9wPgo8cD4gICAguPm+3dauyc+1xLnm1PKjrM7Sw8e1xENTU8jnz8LL+cq+PC9wPgo8cD48cHJlIGNsYXNzPQ=="brush:java;">a {color: #00c;}a.mailto {background: url(images/email.png) no-repeat right top;padding-right: 18px;}a.pdflink {background: url(images/pdf.png) no-repeat right top;padding-right: 18px;}a.henrylink {background-color: #fff;padding: 2px;border: 1px solid #000;}


那麼,jQuery的屬性怎麼樣表示呢?

jQuery選取器[屬性]


為了簡化選取器代碼,我們使用符號匹配。

“^” 開頭匹配

“$” 結尾匹配

“*” 包含匹配

$('a[href^="mailto"]').addClass('mailto');$('a[href$=".pdf"]').addClass('pdflink');$('a[href*="henry"]').addClass('henrylink');

實現的效果如:



我們不希望“email”使用“henrylink”樣式,對“Henry V”進一步具體限制

$('a[href*="henry"][href^="http"]').addClass('henrylink');

最終實現效果:



附:

chapter02.css

@charset "utf-8";/* CSS Document */.horizontal {float: left;list-style: none;margin: 10px;}.sub-level {background: #ccc;}a {color: #00c;}a.mailto {background: url(images/email.png) no-repeat right top;padding-right: 18px;}a.pdflink {background: url(images/pdf.png) no-repeat right top;padding-right: 18px;}a.henrylink {background-color: #fff;padding: 2px;border: 1px solid #000;}

chapter02.js

$(document).ready(function() {    $('#selected-plays > li').addClass('horizontal');// add$('#selected-plays li:not(.horizontal)').addClass('sub-level');// Section II$('a[href^="mailto"]').addClass('mailto');$('a[href$=".pdf"]').addClass('pdflink');$('a[href*="henry"][href^="http"]').addClass('henrylink');});

html檔案(chapter02.html)詳見《學習JQuery - 2》




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.