使用jQuery替换HTML5首字母缩略词标记
使用jQuery,如何将每个使用jQuery替换HTML5首字母缩略词标记,jquery,html,Jquery,Html,使用jQuery,如何将每个标记替换为?$(“首字母缩写”)。每个(函数(){ var$this=$(this); $this.before(“”+$this.html()+“”); $this.remove(); }); 我想试试这个,但我不提供保修 $('acronym').each(function(index) { var old = this; var newElement = $("<abbr></abbr>"); $.each(this.att
标记替换为
?$(“首字母缩写”)。每个(函数(){
var$this=$(this);
$this.before(“”+$this.html()+“”);
$this.remove();
});
我想试试这个,但我不提供保修
$('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();
});
$('acronym')。每个(函数(索引)
{
var old=这个;
var newElement=$(“”);
$.each(this.attributes,function(index)
{
$(新元素).attr(old.attributes[index].name,old.attributes[index].value);
});
$(newElement.html(old.html());
$(this).after(newElement.remove();
});
祝你好运,告诉我是不是坏了。如果它被破坏了,我将尝试修复它。使用jQuery的。我假设您只使用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!
});
$(“首字母缩略词”).each(function(){//用于每个首字母缩略词元素
var abbr=$(“大致如下:
$('acronym').each(function(i, el) {
$(this).replaceWith($('<abbr></abbr>').html($(this).html()));
});
$('acronym')。每个(函数(i,el){
$(此)。替换为($('
编辑:如果你有任何属性,你也会想要复制属性……当然你没有
- 基督教徒
$('acronym')。每个(函数(){
$(this.replacetwith(“”+$(this.html()+“”);
});
$(“首字母缩写”)。每个(函数(idx、HTML){
$(this).替换为(“”+HTML+“”);
});
您还需要复制任何属性:您忘记了复制原始标记的内容。不确定为什么要在jQuery或JavaScript full stop中执行此操作。正确的标记应该写入HTML文档,或者更好的是,保留XML或JSON术语表(在服务器端)和转换HTML中术语文本节点的实例,方法是使用缩写标记将它们包装起来。
$('acronym').each(function(i, el) {
$(this).replaceWith($('<abbr></abbr>').html($(this).html()));
});
$('acronym').each(function() {
$(this).replaceWith('<abbr>' + $(this).html() + '</abbr>');
});
$("acronym").each(function(idx,HTML) {
$(this).replaceWith('<abbr title="'+this.title+'">'+HTML+'</abbr>');
});