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