• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

1.实现步骤

(1)定义模板结构

(2)预调用模板引擎

(3)封装模板函数

(4)导入并使用自定义的模板引擎

定义模板结构

fbu3xzt4nx54603.png

//定义数据

var data={ name: 'zs ',年龄: 28,性别: '男,地址: '北京顺义马坡' }

//调用模板引擎

var htmlStr=template('tpl-user ',data)

//渲染超文本标记语言结构

文档。getelementbyid(“用户框”).innerHTML=htmlStr

封装函数调用

函数模板(id,数据){

var str=文档。getelementbyid(id).innerHTML

var pattern=/{ { \ s *(a-zA-Z))\ s * } }/

定义变量模式=空

while((patt结果=模式。exec(str))){

str=str.replace(模式结果[0],数据[模式结果[1]])

}

返回字符串

}

Link to comment
Share on other sites