我已經在div中添加了5個文件,使用appendTo,現在我想獲取所有這些文件的src。我如何着手使用jQuery來獲取它。我可以使用.get()嗎?得到一個鏈接的jrc jQuery
感謝 讓
[編輯]
<div id="some">
<img src="jquery_book.jpg"><a href="jquery.pdf">JQuery Book</a>
</div>
我需要src和HREF。
我已經在div中添加了5個文件,使用appendTo,現在我想獲取所有這些文件的src。我如何着手使用jQuery來獲取它。我可以使用.get()嗎?得到一個鏈接的jrc jQuery
感謝 讓
[編輯]
<div id="some">
<img src="jquery_book.jpg"><a href="jquery.pdf">JQuery Book</a>
</div>
我需要src和HREF。
不知道你在文件意味着什麼,但你可以得到屬性這樣的:根據您的更新答
$("selector").attr('src');
:
$('#some a').each(function(){
alert ($(this).attr('href'));
});
喜歡的東西
var arrsource = new Array();
$("#yourdivid a").each(function(){
arrSource.push ($(this).attr("href"));
});
不使用數組
$("#yourdivid a").each(function(){
var currentElemSource = $(this).attr("href");
// write your code here
});
編輯
$("#some a").each(function(){
var currentElem = $(this);
var imageSource = currentElem.prev().attr("src");
var path = currentElem.attr("href");
});
我假設你正在使用錨標記,你已經得到了在HREF路徑。
你可以請張貼一些代碼? – 2010-03-04 11:26:50
你能發佈你的HTML標記嗎? – rahul 2010-03-04 11:26:53
@rahul @ .j 發佈了html代碼 – X10nD 2010-03-04 11:40:40