使用jQuery更改链接标题的问题 [英] Issue with changing the title of a link using jQuery
问题描述
我一直在尝试使用JQuery更改链接的标题.基本上,即使我键入www.hotmail.com,我当前的主题也存在一个问题,无法将某些内容识别为URL.我想:
I have been trying to change the title of a link using JQuery. Basically my current theme has an issue identifying something as a URL even though I keyed in www.hotmail.com. I would like to:
(1)使它认识到它是指向www.hotmail.com的链接
(1) Get it to recognize that it is a link to www.hotmail.com
(2)将名称www.hotmail.com更改为Click Here
(2) Change the name www.hotmail.com to Click Here
I have tried to implement what was mentioned in this thread but have been unsuccessful (How do I change the title of a link using jQuery).
单击后,我可以直接访问www.hotmail.com,但文本不会更改为单击此处".
I was able to get the link to direct to www.hotmail.com upon clicking but the text does not change to Click Here.
我的代码:
var href = jQuery('p.item-property').html();
var link = "<a href='"+href+"' target='_blank'>"+href+"</a>";
jQuery('p.item-property').replaceWith(link);
$('p.item-property').text('Click Here');
推荐答案
您的选择器标识与您用link
替换的元素相对应的元素.您想改为更改link
的text
:
Your selector identifies the elements corresponding the elements you have replaced with link
. You wanted to change the text
of link
instead:
var href = jQuery('p.item-property').html();
var link = "<a href='"+href+"' target='_blank'>"+href+"</a>";
jQuery('p.item-property').replaceWith(link);
$(link).text('Click Here');
,但最好在初始化时设置正确的text
but it is even better to set the correct text
at initialization
var href = jQuery('p.item-property').html();
var link = "<a href='"+href+"' target='_blank'>Click Here</a>";
jQuery('p.item-property').replaceWith(link);
这篇关于使用jQuery更改链接标题的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!