Click on the link to insert the link content.
Highlight:
1. Regular match <a> mark.
2.jQuery Click Add, double-click Delete.
3.textarea Add line wrapping.
Core code:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>click to Text</title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta http-equiv= "Content-language" content= "ZH-CN"/>
<script type= "Text/javascript" src= "Http://demo.jb51.net/jslib/jquery/jquery-1.6.2.min.js" ></script>
<body>
<div id= "Clickcontain" >
<a href= "Http://www.jb51.net" > Cloud-dwelling Community </a>
<a href= "http://www.baidu.com" > Baidu </a>
<a href= "http://www.qq.com" >QQ</a>
<a href= "http://www.sina.com.cn" > Sina </a>
<a href= "http://www.sina.com.cn" >abc</a>
</div>
<div id= "Textcontain" >
<textarea rows= "Ten" cols= "></textarea>"
</div>
<script type= "Text/javascript" >
$ (document). Ready (function () {
var Textareacontain = $ ("#textContain textarea"). EQ (0);
Click Insert Link
$ ("#clickContain a"). Click (function () {
if (!$ (this). Hasclass (' lock ')) {
var p = eval ('/<a (?:. *) ' +$ (this). html () + ' (?:. *) a>/i ');
var addstring = $ (this). Parent (). HTML (). Match (P); Regular extraction <a> Labeling
if (!! addstring) addstring = addstring[0]+ ' \ n '; A regular match of [0] is all the matching values, adding a newline \ n
Textareacontain.val (Textareacontain.val () +addstring);
$ (this). addclass (' lock '); Block Second Click
}
return false;
});
Double-click Delete link
$ ("#clickContain a"). DblClick (function () {
$ (this). attr (' class ', null); Remove the entire class attribute to avoid class= ""
var p = eval ('/<a (?:. *) ' +$ (this). html () + ' (?:. *) a> (\\n*)/gi ');
Textareacontain.val (Textareacontain.val (). Replace (P, '));
return false;
});
});
</script>
</body>
Author: Zjmainstay
Source: http://www.cnblogs.com/Zjmainstay/