|Home|Knowledge|Economic&M|Technology|English|PCFAQ|Read|See|Football|Writing|July|TagS|

 Placard

加载中...

Category
加载中...
Calendar
加载中...
Latest Entries
加载中...
Latest Comments
加载中...
Last Messages
加载中...
Links
Information
加载中...
Search
Other

          人生没有彩排,每天都是现场直播! 

  Javascript特效:将HTML自动转为JS代码
 

有时候要用Javascript输常用的字符,比如每个页面都要有的脚注。这里提供一个转换脚本:

{ var value = val.value value = value.replace(/\\/gi,"\\\\").replace(/"/gi,"\\\"").replace(/'/gi,"\\\'") valArr = value.split("\r\n") value="" for (i=0; i

源:

{
 var value = val.value
 value  = value.replace(/\\/gi,"\\\\").replace(/"/gi,"\\\"").replace(/'/gi,"\\\'")
 valArr = value.split("\r\n")
 value=""
 
 for (i=0; i<valArr.length; i++)
 {
  value += (i==0) ? "info =" : ""
  value += "  \"" + valArr[i]
  value += (i!=valArr.length-1) ? "\" +\"\\n\"+\n" : "\"\n"
 }
 value+="\ndocument.write(info)"
 
 val.value = value
}
</script>

<input type=button value="将 HTML 转为 JavaScript" onclick=toScript(document.all["code"])><br>
<textarea id=code cols=75 rows=20>
<table width="200" border="1">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table></textarea>

阅读全文 | 回复(0) | 引用通告 | 编辑   

  Post  by  醉无心 发表于 2008-4-3 11:38:00
  • 标签:html 
  • 发表评论:
    加载中...

    Google

     

    Power By 加载中...

    Powered by Oblog.