将每一行textarea变成一个链接 [英] Turn each line of textarea into a link
本文介绍了将每一行textarea变成一个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,假设我有一个文本区域和一个切换按钮:
Let's say for example i have a textarea and a toggle button:
<div class="input">
<textarea id="links">
http://facebook.com
http://friendster.com
http://google.com
http://facebook.com
http://friendster.com
</textarea>
<a href="#" class="toggle">Toggle</a>
</div>
如何通过单击切换按钮使文本区域中的每个链接都可单击?
How do i make it possible for each link in the textarea to clickable with the click of the toggle button?
$('.toggle').click(function(){
var clickable = false;
if(!clickable){
var links = $(this).closest('.input').find('textarea').val().split('\n');
$.each(links,function(){
//lost here
});
}
return false;
});
推荐答案
您无法在textarea中创建可点击的链接,它们是用于纯文本的.
You cannot make clickable links inside textarea, they are for a plain text.
但是,有可能的解决方法,您可以创建一个div,单击"Toggle"时将textarea的格式化内容复制到该div,然后切换textarea和div.
There are possible workarounds though, you can make a div, copy formatted content of textarea to this div, when "Toggle" is clicked, and switch textarea and div.
这篇关于将每一行textarea变成一个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文