JavaScript實現(xiàn)存儲HTML字符串示例
更新時間:2014年04月21日 17:26:20 作者:
這篇文章主要介紹了JavaScript存儲HTML字符串的具體實現(xiàn),需要的朋友可以參考下
我是搞PHP的,讓我想起了<<<語法(heredoc和nowdoc),那么就為他命名heredoc吧。
Function.prototype.heredoc = function(){
// 利用 function 的注釋來存儲字符串,而且無需轉(zhuǎn)義。
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 的注釋來存儲字符串,而且無需轉(zhuǎn)義。
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);
相關文章
Javascript實現(xiàn)簡單的富文本編輯器附演示
這篇文章主要介紹了通過Javascript實現(xiàn)的簡單富文本編輯器,需要的朋友可以參考下2014-06-06echartjs實現(xiàn)cross十星輔助線實現(xiàn)示例詳解
這篇文章主要為大家介紹了echartjs實現(xiàn)cross十星輔助線實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12uniapp頁面通訊講解之uni.$emit、uni.$on、uni.$once和uni.$off
uni-app?是一個使用vue.js開發(fā)所有前端應用的框架,下面這篇文章主要給大家介紹了關于uniapp頁面通訊之uni.$emit、uni.$on、uni.$once和uni.$off的相關資料,需要的朋友可以參考下2022-09-09JS按鈕倒計時并跳轉(zhuǎn)到新地址的實現(xiàn)代碼
在完成某項操作時,按鈕上有個倒計時效果,倒計時結束后,跳轉(zhuǎn)到新地址,這篇文章主要介紹了JS按鈕倒計時并跳轉(zhuǎn)到新地址,需要的朋友可以參考下2023-02-02