zl程序教程

您现在的位置是:首页 >  前端

当前栏目

JavaScript实现存储HTML字符串示例

JavaScript存储HTML 实现 字符串 示例
2023-06-13 09:15:25 时间
我是搞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);
}

functionfn(){
/*<table>
<tr>
<td>用户名</td>
<td>密码</td>
</tr>
<tr>
<tdstyle="widht:20px;">@name</td>
<td>zf123456</td>
</tr>
</table>*/
}

varstr_table=fn.heredoc();
console.log(str_table);