jQuery - Identify and mark link in textarea

人走茶凉 提交于 2019-12-12 05:15:04

问题


I have a textarea

<textarea id="postContent" class="input-block-level" placeholder="Tell us about it!" rows="4"></textarea>

and I need a script that highlights the links written inside the textarea, stores them in a variable (array) for later processing and removes all html-tags. The behavior is well-know from the tweet-box on twitter.

So the content could be

Look what I have found today on www.stackoverflow.com!

and in that case, www.stackoverflow.com should be highlighted (wrapped in a <p> f.e.) without the "!".

How would you do that with jQuery?


回答1:


If you want to highlight link then you have to work with innerHTML of textarea....(I would not suggest that) your regex goes here = var regEx = /((ht|f)tps?://\S*)/g;

Secondly, you can identify links using click event inside textarea...click handler should look whether it is a url or plain text..if a link open new window..else return false....



来源:https://stackoverflow.com/questions/14706211/jquery-identify-and-mark-link-in-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!