2014-04-01 35 views
0

我一直在试图让所有存在的链接,并改变它们的title属性,如果他们的标题属性包含“固定链接到”。到目前为止,我有这一小段代码,删除所有title属性的链接,但我一直没能得到任何代码的工作,以检测是否“永久链接”的称号属性存在,如果是从标题中删除。 任何想法,帮助将不胜感激,谢谢。JQuery的变化都HREF title属性

$(document).ready(function($) { 

//gets all links and removes 'Permalink to ' from title attribute if exists 
var l = $('a'); 

//removes title attribute from all links 
l.removeAttr('title'); 

}); 

下面是一个的jsfiddle我有工作@http://jsfiddle.net/M5F8P/1/

+0

我认为不正确实施到运的question.He答案要编辑的属性文本,而不是将其删除。 – HenryW

回答

0

希望这有助于

$(document).ready(function($) { 
    $("a").each(function(index) { 
     $(this).removeAttr('title'); 
    }); 
}); 
1

例如:

l.each(function(){ 
    var $me = $(this); 
    $me.attr('title', $me.attr('title').replace('Permalink to', ''); 
}); 
+0

你是最亲密的,它让我用你的代码和一点研究一起工作。谢谢 –

2

你可以做你的选择到外卡寻找所有标题包含'Permanent'的标签:

$(document).ready(function($) { 
$('a[title*="Permalink"]').removeAttr('title'); 
}); 
0

这段代码在每一个环节元素,其标题中包含“固定链接到”改变title属性为“新头衔”。只需用适当更改的标题替换“新标题”即可。

$(document).ready(function($) { 
    $('a').each(function(){ 
     var $this = $(this); 
     if (/Permalink to/.test($this.attr('title'))) { 
      // replace title attribute with new/changed value 
      $this.attr('title', 'new title'); 
     }; 
    }); 
}); 

JSFiddle

/Permalink to/RegExp,你可以调整它为您的需求。例如,/^Permalink to /将只匹配标题与“永久”启动/Permalink to/i将不区分大小写。