JavaScript实现存储HTML字符串示例
更新时间:2014年04月21日 17:26:20 作者:
这篇文章主要介绍了JavaScript存储HTML字符串的具体实现,需要的朋友可以参考下
我是搞PHP的,让我想起了<<<语法(heredoc和nowdoc),那么就为他命名heredoc吧。
Function.prototype.heredoc = function(){
// 利用 function 的注释来存储字符串,而且无需转义。
var _str = this.toString(),
s_pos = _str.indexOf("/*")+2,
e_pos = _str.lastIndexOf("*/");
return (s_pos<0 || e_pos<0) ? "" : _str.substring(s_pos, e_pos);
}
function fn(){
/*<table>
<tr>
<td>用户名</td>
<td>密码</td>
</tr>
<tr>
<td style="widht:20px;">@name</td>
<td>zf123456</td>
</tr>
</table>*/
}
var str_table = fn.heredoc();
console.log(str_table);
复制代码 代码如下:
Function.prototype.heredoc = function(){
// 利用 function 的注释来存储字符串,而且无需转义。
var _str = this.toString(),
s_pos = _str.indexOf("/*")+2,
e_pos = _str.lastIndexOf("*/");
return (s_pos<0 || e_pos<0) ? "" : _str.substring(s_pos, e_pos);
}
function fn(){
/*<table>
<tr>
<td>用户名</td>
<td>密码</td>
</tr>
<tr>
<td style="widht:20px;">@name</td>
<td>zf123456</td>
</tr>
</table>*/
}
var str_table = fn.heredoc();
console.log(str_table);
相关文章
uniapp页面通讯讲解之uni.$emit、uni.$on、uni.$once和uni.$off
uni-app 是一个使用vue.js开发所有前端应用的框架,下面这篇文章主要给大家介绍了关于uniapp页面通讯之uni.$emit、uni.$on、uni.$once和uni.$off的相关资料,需要的朋友可以参考下2022-09-09
最新评论