如何在jQuery中使用链接查找和替换文本URL [英] how to find and replace text url with links in jquery
本文介绍了如何在jQuery中使用链接查找和替换文本URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在编辑器中找到文本url,然后使用jquery将其转换为锚标记链接.
Hi I want to find text url in my editor and convert them to anchor tag links using jquery.
这是我的代码
function urlify(text) {
var urlRegex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
return text.replace(urlRegex, function(url) {
return '<a href="' + url + '">' + url + '</a>';
})
}
$("#queEditor").bind('input propertychange', function(){
var url = urlify($("#queEditor").text);
console.log(url);
});
但是它给出了错误的未定义函数文本.有人可以帮我纠正这个问题吗?
But it's giving an error undefined function text. Could someone help me rectify this?
推荐答案
由于.text()
是一个函数,您需要在调用它时使用()
.
Since .text()
is a function you need to use ()
when you want to invoke it.
$("#queEditor").text(); //Notice ()
这篇关于如何在jQuery中使用链接查找和替换文本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文