jQuery文本链接脚本? [英] jQuery Text to Link Script?
问题描述
有谁知道一个脚本可以选择所有的URL引用文本,并自动将它们替换为指向这些位置的锚标签?
例如:
http://www.google.com
会自动变成
< a href =http ://www.google.com> HTTP://www.google.com< / A>
注意:我想这样做是因为我不想浏览所有内容并包装它们与锚标签。
JQuery在这里不会帮你一大堆,因为你并不真正关心DOM遍历/操作除了创建锚标签)。如果您的所有网址都位于< p class =url>标签则可能。
一个vanilla JavaScript解决方案可能是您想要的,并且命运会如此,这个人应该有你覆盖。
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 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.
A vanilla JavaScript solution is probably what you want, and as fate would have it, this guy should have you covered.
这篇关于jQuery文本链接脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!