HandleBars เป็นไลบรารีเทมเพลตหน้า JavaScript ที่ช่วยให้คุณสร้างเทมเพลตความหมายได้อย่างง่ายดาย
การคัดลอกรหัสมีดังนี้:
<! doctype html public "-// w3c // dtd html 4.01 transitional // en">
<html>
<head>
<title> handlebars </title>
<meta http-equiv = "คำหลัก" content = "keyword1, keyword2, keyword3">
<meta http-equiv = "คำอธิบาย" content = "นี่คือหน้าของฉัน">
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<script src = "$ {base} /js/jquery1.11.min.js"> </script>
<script src = "$ {base} /js/handlebars-v3.0.0.js"> </script>
</head>
<body>
<div id = tt style = 'display: none'>
<div>
<H1> {{title}} </h1>
<div> {{body}} </div>
</div>
</div>
</body>
<script type = "text/javascript">
//$('#tt').Before('<script id = "Temp" type = "sfd"> ');
//$(' นี
var source = $ ("#tt"). html ();
// การแจ้งเตือน (แหล่งที่มา);
เทมเพลต var = handlebars.compile (แหล่งที่มา);
var data = {title: "โพสต์ใหม่ของฉัน", body: "นี่เป็นโพสต์แรกของฉัน!"
-
var result = template (data); // กรอกข้อมูลลงในเทมเพลต
console.log (ผลลัพธ์);
$ ('#tt'). ก่อน (ผลลัพธ์);
</script>
</html>
ตัวอย่างง่ายมาก สำหรับรายละเอียดโปรดดูบทความของ ThinkVitamin ที่เริ่มต้นด้วย handlebars.js ฉันหวังว่าคุณจะชอบมัน