JavaScript实现存储HTML字符串示例

时间:2014-04-21    点击:86   
我是搞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);
div失去焦点事件实现思路
js隐式全局变量造成的bug示例代码
JavaScript实现的图像模糊算法代码分享
JavaScript闭包实例讲解
JavaScript函数的4种调用方法详解
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved