A click link based on jquery inserts the code for the link content _jquery

Source: Internet
Author: User
Tags eval
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/

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.