使用jQuery,您將如何替換每個<acronym>
標記與<abbr>
?使用jQuery的HTML5首字母縮略詞標記替換
2
A
回答
3
$('acronym').each(function() {
var $this = $(this);
$this.before('<abbr>' + $this.html() + '</abbr>');
$this.remove();
});
+0
比我的簡單。它適用於所有情況下的99%,因此+1 – Blender 2010-12-21 02:50:54
+2
您也想要複製任何屬性:http://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element -with-javascript-jquery – 2010-12-21 02:51:18
2
我想試試這個,但我不提供保修。
$('acronym').each(function(index)
{
var old = this;
var newElement = $("<abbr></abbr>");
$.each(this.attributes, function(index)
{
$(newElement).attr(old.attributes[index].name, old.attributes[index].value);
});
$(newElement).html(old.html());
$(this).after(newElement).remove();
});
祝你好運,並告訴我它是否被破壞。如果它被破壞了,我會嘗試修復它。
1
使用jQuery的replaceWith。我假設你只使用title屬性。
$("acronym").each(function(){//for each acronym element
var abbr = $("<abbr></abbr>");//create a new abbr element
var title = $(this).attr("title");//get the title attribute from the acronym element
abbr.attr("title",title);//add it to the new abbr element
abbr.html($(this).html());//add in the content of the acronym element
$(this).replaceWith(abbr);//replace the old with the new!
});
1
東西線沿線的:
$('acronym').each(function(i, el) {
$(this).replaceWith($('<abbr></abbr>').html($(this).html()));
});
編輯:你想複製過的屬性,如果您有任何...理所當然你沒有。
- 基督教
1
$('acronym').each(function() {
$(this).replaceWith('<abbr>' + $(this).html() + '</abbr>');
});
1
$("acronym").each(function(idx,HTML) {
$(this).replaceWith('<abbr title="'+this.title+'">'+HTML+'</abbr>');
});
相關問題
- 1. 駱駝套管首字母縮略詞?
- 2. 專有名詞檢測首字母縮寫詞縮略語
- 3. 避免使用首字母縮略詞嗎?
- 4. 使用VIM製作首字母縮略詞?
- 5. 用於文本挖掘的首字母縮略詞列表
- 6. 使用JSoup替換字母標記
- 7. 使用LINQ從C#中的字符串獲取首字母縮略詞?
- 8. SPI和GDO,什麼是GDO的首字母縮略詞?
- 9. 如何處理類名稱中的首字母縮略詞?
- 10. JavaScript上沒有循環的首字母縮略詞功能
- 11. Visual Studio 2010中的首字母縮略詞菜單在哪裏?
- 12. 什麼是MIPS首字母縮略詞中的「互鎖管道」?
- 13. 智能搜索Salesforce中的首字母縮略詞
- 14. SAS是代表統計分析系統的首字母縮寫,還是絕不是首字母縮略詞?
- 15. c3p0首字母縮略詞來源 - jdbc連接池名稱
- 16. 如何在pdf文件中查找首字母縮略詞
- 17. 在Python中創建首字母縮略詞
- 18. Rails首字母縮略詞轉折分裂中短名稱
- 19. NSArray排序問題與首字母縮略詞排序第一
- 20. HTML首字母縮略詞表 - 顯示鼠標懸停的意義
- 21. 在def函數中將輸入轉換爲首字母縮略詞?
- 22. 使用正則表達式查找首字母縮寫詞Dreamweaver
- 23. 在Rails中使用titleize作爲首字母縮寫詞
- 24. 用jquery替換字詞
- 25. 使用xslt:analyze-string將首字母縮略詞添加到HTML - 現在使用同義詞
- 26. 如何從任何字符串中獲取首字母縮略詞?
- 27. Python:使用首字母縮寫命名
- 28. 使用jquery替換span標記的類
- 29. 首字母大寫從MySQL與PHP/jQuery拉的每個單詞的首字母
- 30. 正則表達式來刪除首字母縮略詞中的句點?
不知道你爲什麼會想這樣做jQuery的,或JavaScript句號。正確的標記應該寫入HTML文檔 - 或者甚至更好的是,在XML或JSON(服務器端)保留術語詞彙表,並通過用縮寫標記包裝HTML中的術語文本節點實例。 – DigiKev 2012-07-06 22:55:19