jQuery 在找到特定文本字符串时添加属性
我的问题是,我有一组使用 jQuery 调用的推文,但它以纯文本形式调用它们。我的目标是让任何带有 http:// 自动链接的东西。在本例中,类似这样:
<a href="{link}"> {link} </a>
将 {link} 替换为插入的实际链接。例如,如果我有一条推文:“访问这个很酷的链接!http://foo.com/”我希望该链接能够真正起作用,因为现在它只是纯文本,因此不可单击。
提前致谢! :)
编辑:这是我迄今为止所拥有内容的链接。 http://jsfiddle.net/Remixz/uCk4s/
My issue is that I have a group of tweets being called in with jQuery, but its calling them in all as plain text. My goal would be to have any thing with an http:// automatically linked. In this case, something like this:
<a href="{link}"> {link} </a>
With {link} being replaced with the actual link inserted. For example, if I have a tweet that says, "Visit this cool link! http://foo.com/" I'd want the link to actually work, as right now its just plain text, and therefore not clickable.
Thanks in advance! :)
EDIT: Here's a link to what I have so far. http://jsfiddle.net/Remixz/uCk4s/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个问题的已接受答案:如何用链接替换普通 URL?< /a>
我认为这正是您所寻找的。
我已经分叉了您在 github 上使用的插件,并对其进行了更新以包含 linkify 功能。以下是更新版本的演示:http://jsfiddle.net/Ender/CrzCZ/
这是 github 上更新的插件: https://github.com/ender2021/jQuery-Tweets/raw/master/js/jquery.tweets.0.1.js
Have a look at this accepted answer to this question: How to replace plain URLs with links?
I think that does exactly what you are looking for.
I've forked the plug-in you were using on github and made an update to it to include the linkify function. Here's a demo of the updated version in action: http://jsfiddle.net/Ender/CrzCZ/
And here's the updated plug-in on github: https://github.com/ender2021/jQuery-Tweets/raw/master/js/jquery.tweets.0.1.js