使用jQuery更改链接标题的问题 [英] Issue with changing the title of a link using jQuery

查看:73
本文介绍了使用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替换的元素相对应的元素.您想改为更改linktext:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆