任何人都有一个线索,我可以如何使用JQuery找到: http://或www。与.COM结尾,.ORG,埃杜 店,作为一个变量,敷在jquery识别并制作超链接
<a href="variable"> <a/>
所以我有一个textarea,当放链接的人,我想,然后使它们成为一次超链接他们被张贴。
有意义吗?
任何人都有一个线索,我可以如何使用JQuery找到: http://或www。与.COM结尾,.ORG,埃杜 店,作为一个变量,敷在jquery识别并制作超链接
<a href="variable"> <a/>
所以我有一个textarea,当放链接的人,我想,然后使它们成为一次超链接他们被张贴。
有意义吗?
可以说文本区域包含,
http://site1.com/uri/
http://site2.net/uri
http://site3.org/uri
http://site4.co.uk/uri
http://site5.ws/uri
我会做的第一件事就是绑定的即使对文字区域的键控也是如此
$('#addLinks').bind('keyup',function(){
var _data = $(this).val();
//Then i would try and split the spaces and carriages
_array = _data.split('\n|\r\n|\s|,'); //Split by returns,new lines,spaces,commas.
var _regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
$(_array).each(function(value){
//Now i will check the URL is valid
if(_regex.test(value))
{
//Valid URL so i will then append it to the links container
//Here you can do e
$('<a></a>').attr('href',value).val(value).appendTo('.linksContainer');
}
})
});
沿着它们的线条!
滚你自己的方式:
var foo = $('textarea selector').val();
然后使用正则表达式来得到你想要的。然后坚持它放回textarea的
$('textarea selector').val('http://thenewlink');
简单的插件方式:
如果你不想这样做,直到它们被贴了,你想与服务器端的代码,而不是要做到这一点jQuery的。如果您在提交之前使用JS创建帖子的预览,那么使用jquery会很有意义。 – intuited 2010-06-08 02:56:55