将文本动态转换为链接 [英] convert text into link dynamically
本文介绍了将文本动态转换为链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文字转换成链接
我得到了这个 - >
我有用户输入描述的textarea。
我的表有列(名称),其中有4个名字(jack,drake,joey,pacino)。
现在,如果文本中有任何单词,则上述4个单词,文本会自动更改为链接。
我该怎么做。
例如:
teatarea输入:你好joey,我和德雷克正在上演。
输出:你好 joey ,我和德雷克正在进行。
解决方案
我提出了你的问题,因为你提出了一个有趣的问题(对我而言)。正如我在评论中提到的,我怀疑你可以在textarea中做类似的事情。仅仅因为textareas不支持任何格式。您可能想知道基于Web的WYSIWYG编辑器是如何工作的 - 好吧,他们不依赖于textareas,他们做其他事情。在HTML5中,您有一个简洁的属性,名为contenteditable
,它可以实现它的承诺。它让生活更轻松,但并不那么容易。我做了一些可能看起来像你想要的东西。
< html >
< head >
< script src = http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js > < / script >
< script 类型 = text / javascript >
var needles = new Array();
函数evalNeedles()
{
needle =
('#needle')。val()。split(',' );
}
函数句柄()
{
var editor =
('#editor');
I want to convert text into link
I got this->
I have a textarea in which user enter description.
I have table having column (name) in which there are 4 names (jack , drake , joey , pacino).
Now , if any word in the text the above 4 word , the text gets automatically changed to a link.
How can i do that.
Eg:
teatarea input: hello joey , me and drake are going.
output: hello joey , me and drake are going.
解决方案
I have upvoted your question because you have presented an interesting problem (for me). As I mentioned in my comment, I doubt you can do something like that in a textarea. Simply because textareas do not support any formatting. You might be wondering how web based WYSIWYG editors work - well, they do not rely on textareas, they do other stuff. In HTML5 you have a neat attribute, namedcontenteditable
which makes what it promises. It makes life easier, but not that easy. I have made something that might look like what you wanted.
<html> <head> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"></script> <script type="text/javascript"> var needles = new Array(); function evalNeedles() { needles =
('#needle').val().split(','); } function handle() { var editor =
('#editor');
这篇关于将文本动态转换为链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文