Simple template replacement mechanism-jquery implements partial

Source: Internet
Author: User

Simple template replacement mechanism-jquery implements partial

Today, several attributes of the current element need to be used in the effect prompt of a Tip prompt for colleagues to modify the demo.
Here is a local implementation for Reference

View: Temporary Demo
Case study: click here

Copy to ClipboardReference: [www.bkjia.com] <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.1 // EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> A jquery small template mechanism-I am UED </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Script language = "JavaScript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
</Head>
<Body>
<A id = "test" price = "110" name = "iphone" onmouseover = "test (); "href =" # "> This is an A. Element a has two attributes. move the cursor over it. </A>

Some code of the temporary Demo:
<Script type = "text/javascript">
Function test (){
Var testString = "the price is {price} RMB, I am {name }"
Alert (testString. replace (/{([^ {}] +)}/g, function (word ){
Var _ attr = word. replace (/({|}) +/g ,"");
Return $ ("# test"). attr (_ attr );
}));
}
</Script>
</Body> This article is reproduced by the fire, the following is the author and link. If you need to repost it, please keep the following link; otherwise, it will be deemed as infringement.

I'm UED: http://www.iamued.com/

Link: http://www.iamued.com/qianduan/js/1718.html

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.