问题
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