Jquery-based code for clicking a link to insert link content

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.