<html>
<body>
<script language="javascript">
function $(id){
return document.getElementById(id)
}
person=function(html,o){
me = this
me.html=html
me.html = me.compile(o)
}
person.prototype={
re:/\{([\w-]+)\}/g,
compile:function(values){
me = this
return me.html.replace(me.re, function(m,name){
return values[name] !== undefined ? values[name] : "";
})
},
html:function(){
return this.html
}()
}
function alt(id){
$(id).innerHTML = new person("您的名字是:{name},您的编号是:{id}",{id:'007',name:'占姆斯·邦德'}).html
}
/*
* HTML模版 可以使用AJAX查询得到JSON进行替换。
*
*/
</script>
<div id="test"><a href="javascript:void(0)" onclick="alt('test')">点击查询</a></div>
</body>
</html>
Jan.20105
正在加载
