Click the link to insert the link content.
Highlights:
1. Regular Expression matching <a> mark.
2. Click Add in jQuery and double-click Delete.
3. Add a line feed to textarea.
Core code:
Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<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>
</Head>
<Body>
<Div id = "clickContain">
<A href = "http://www.jb51.net"> foot home </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 = "10" cols = "50"> </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 ('/<(? :. * Choose '{}(this}.html () + '(? :. *) A>/I ');
Var addString = signature (this).parent().html (). match (p); // Regular Expression extraction <a> tag
If (!! AddString) addString = addString [0] + '\ n'; // [0] After regular expression matching is all matched values. Add the line feed \ n
TextareaContain. val (textareaContain. val () + addString );
$ (This). addClass ('lock'); // block the second click
}
Return false;
});
// Double-click the delete Link
$ ("# ClickContain a"). dblclick (function (){
$ (This). attr ('class', null); // Delete the entire class attribute to avoid class = ""
Var p = eval ('/<(? :. * Choose '{}(this}.html () + '(? :. *) A> (\ n *)/G ');
TextareaContain. val (textareaContain. val (). replace (p ,''));
Return false;
});
});
</Script>
</Body>
</Html>
Author: Zjmainstay
Source: http://www.cnblogs.com/Zjmainstay/