Home >Web Front-end >JS Tutorial >Automatically convert HTML to JS code_JavaScript

Automatically convert HTML to JS code_JavaScript

WBOY
WBOYOriginal
2016-05-16 19:28:511014browse
<script><BR>function toScript(val)<BR>{<BR> var value = val.value<BR> value = value.replace(/\\/gi,"\\\\").replace(/"/gi,"\\\"").replace(/'/gi,"\\\'")<BR> valArr = value.split("\r\n")<BR> value=""<br><br> for (i=0; i<valArr.length; i++)<BR> {<BR> value += (i==0) ? "info =" : ""<BR> value += " \"" + valArr[i]<BR> value += (i!=valArr.length-1) ? "\" +\"\\n\"+\n" : "\"\n" <BR> }<BR> value+="\ndocument.write(info)"<br><br> val.value = value<BR>}<BR></script>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn