0
Q
追加圖標類名
A
回答
1
我修改了腳本以包含在「config」var「target」屬性中。這個「目標」只不過是一個默認爲「this」的jQuery選擇器(比如.class,在這種情況下)。
所以:
jQuery('#hello').favicons({insert: 'insertBefore', target: '.class' }); //aplies to $('.class')
//These 2 are the same
jQuery('#hello').favicons({insert: 'insertBefore', target: '#hello' }); //target is the same as "this"
jQuery('#hello').favicons({insert: 'insertBefore'});
我希望這個作品爲你!
這是一個完整的工作代碼:
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
<script type="text/javascript">
jQuery.fn.favicons = function (conf) {
var config = jQuery.extend({
insert: 'appendTo',
target: this
}, conf);
return this.each(function() {
jQuery('a[href^="http://"]', this).each(function() {
var link = jQuery(this);
var faviconURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1') + '/favicon.ico';
var faviconIMG = jQuery('<img src="' + '" alt="" />')[config.insert]($(config.target));
var extImg = new Image();
extImg.src = faviconURL;
if (extImg.complete) {
faviconIMG.attr('src', faviconURL);
}
else {
extImg.onload = function() {
faviconIMG.attr('src', faviconURL);
};
}
});
});
};
$(function(){
jQuery('#hello').favicons({insert: 'insertBefore', target: '.class' });
});
</script>
</head>
<body>
<p id="hello"><a href="http://www.google.nl/">Google</a></p>
<p class="class">apend favicon over her instead</p>
</body>
</html>
相關問題
- 1. 追加整數目標C變量名
- 2. 追加圖像頂部的圖標
- 3. jQuery的追加不追加風格的圖標正確
- 4. 追加一類
- 5. 追加CSS類
- 6. 追加字符串與視圖名稱
- 7. jQuery追加圖標只有一次
- 8. 的Javascript追加圖標到現場
- 9. 鏈接旁邊的追加圖標
- 10. 定向追加圖像標籤
- 11. 追加div標籤
- 12. 追加到(這)類
- 13. 追加圖片ID
- 14. JQuery追加圖像
- 15. 追加子視圖
- 16. 序言追加名單
- 17. 追加文件名,每行
- 18. 追加後綴到姓名
- 19. 追加PDF的簽名PDF
- 20. 意外的名單追加
- 21. 追加文件名的ElementTree
- 22. php在標題內追加
- 23. 追加標籤JSON響應
- 24. 追加與div和類
- 25. 與追加類if語句
- 26. jQuery追加第二類
- 27. 如何爲nicescroll追加類
- 28. 追加的方法一類
- 29. OutputStream追加文件類型
- 30. Knockout追加到類綁定
太謝謝你了:) – Youss 2012-03-20 13:25:55
也感謝解釋是怎麼回事。 – Youss 2012-03-20 13:26:33
沒問題!快樂的編碼! – fsodano 2012-03-20 15:00:33