JavaScript 页面模板引擎
2015-10-26 15:37
453 查看
varTemplateEngine=function(html,options){ varre=/<%([^%>]+)?%>/g,reExp=/(^()?(if|for|else|switch|case|break|{|}))(.*)?/g,code='varr=[];\n',cursor=0; varadd=function(line,js){ js?(code+=line.match(reExp)?line+'\n':'r.push('+line+');\n'): (code+=line!=''?'r.push("'+line.replace(/"/g,'\\"')+'");\n':''); returnadd; } while(match=re.exec(html)){ add(html.slice(cursor,match.index))(match[1],true); cursor=match.index+match[0].length; } add(html.substr(cursor,html.length-cursor)); code+='returnr.join("");'; returnnewFunction(code.replace(/[\r\t\n]/g,'')).apply(options); }</%([^%>
相关文章推荐
- [转]JS学习之正则表达式
- HTML倒计时JS
- js this关键字
- 去掉jsp编译后的空格
- js基本应用
- jsp获取后台返回的对象中包含的list以及el获取后台json对象并且解析
- ajax 和jsonp 不是一码事 细读详解
- 常用排序算法的JS实现
- MFC JSON解析-开源jsoncpp
- html模板与json数据交互
- Javascript use strict模式和对象
- js中的this关键字详解
- 在JSP中动态生成随机验证码,登录时后台校验验证码,以及如何避免同一个验证码被重复提交爆破密码
- JS调试加断点
- WebGL With Three.js – Lesson 6(转)
- js的运用
- jsf2.0视频
- NSData,NSImage,NSDictionary,NSString,NSURL 等等互相转换
- log4js日志文件库的使用
- JS当中获取Web访问基路径