jQuery 文本链接脚本? [英] jQuery Text to Link Script?

查看:25
本文介绍了jQuery 文本链接脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道可以选择所有指向 URL 的文本引用并自动用指向这些位置的锚标记替换它们的脚本吗?

Does anyone know of a script that can select all text references to URLs and automatically replace them with anchor tags pointing to those locations?

For example:

http://www.google.com 

would automatically turn into

<a href="http://www.google.com">http://www.google.com</a>

注意:我想要这个是因为我不想浏览我的所有内容并用锚标签包装它们.

Note: I am wanting this because I don't want to go through all my content and wrap them with anchor tags.

推荐答案

JQuery 在这里不会帮到你很多,因为你并不真正关心 DOM 遍历/操作(除了创建锚标记).如果您所有的 URL 都在 <p class="url">标签然后也许.

JQuery isn't going to help you a whole lot here as you're not really concerned with DOM traversal/manipulation (other than creating the anchor tag). If all your URLs were in <p class="url"> tags then perhaps.

一个普通的 JavaScript 解决方案可能就是你想要的,而且命运也会如此,这个人应该帮你掩护.

A vanilla JavaScript solution is probably what you want, and as fate would have it, this guy should have you covered.

这篇关于jQuery 文本链接脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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