jquery根據屬性和index來尋找屬性值並操作,jquery屬性值

來源:互聯網
上載者:User

jquery根據屬性和index來尋找屬性值並操作,jquery屬性值

<div class="zy_menu clearfix"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="1" id="assoeted1" class="hover_a">課件庫</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="2" id="assoeted2">課堂實錄</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="3" id="assoeted3">試題庫</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="4" id="assoeted4">教案庫 </a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="5" id="assoeted5">素材庫 </a></div>
var assoeted =5;$(".zy_menu a[rel="+assoeted+"]").removeClass("hover_a").addClass("hover_a");$(".zy_menu a").removeClass("hover_a").eq(assoeted-1).addClass("hover_a");

jquery 怎擷取CSS中屬性值的數值

完全可以替代傳統javascript

比如你要擷取id為123的div的z-index的值
$("#123").css("z-index")
而你要設定他的屬性值的話就是這樣寫
$("#123").css("z-index","10")
 
Jquery先擷取自身內部的元素屬性值,該怎擷取?

jQuery手冊中這樣寫道:
$(expression, [context])
expression String 用來尋找的字串
context (可選) Element, jQuery 作為待尋找的 DOM 元素集、文檔或 jQuery 對象。

那麼,你可以這樣擷取:
$('img:first-child', this).attr('src');

--------------------------------------
或者用原生js:
var a = document.getElementById('my').getElementsByTagName('a');
var src = [];
for(var i=0;i<s.length;i++){
src.push(a[i].getElementsByTagName('img')[0].src);
}
 

聯繫我們

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