admin管理员组文章数量:1323731
On IE Quirks mode, I want to use following code to display some javascript functions on a html page:
document.write('<pre>' + someFunction + '</pre>');
But if a function's source contains '<', only source code ahead of '<' will be displayed.
for example :
function a(j){
var i = 0;
if(i<j){
alert(j + ' is greater than zero');
}
}
will be displayed as :
function a(j){
var i = 0;
if(i
how to make it display the full source code of a function ?
On IE Quirks mode, I want to use following code to display some javascript functions on a html page:
document.write('<pre>' + someFunction + '</pre>');
But if a function's source contains '<', only source code ahead of '<' will be displayed.
for example :
function a(j){
var i = 0;
if(i<j){
alert(j + ' is greater than zero');
}
}
will be displayed as :
function a(j){
var i = 0;
if(i
how to make it display the full source code of a function ?
Share Improve this question asked Dec 29, 2011 at 10:15 CaiNiaoCoderCaiNiaoCoder 3,31910 gold badges53 silver badges82 bronze badges3 Answers
Reset to default 5instead of using that '<' or '>' symbols you can use their html rxpressions.
Eg <
instead of < and >
instead of > .
This will solve your problem . Try this.
Replace <
symbol by <
and >
by >
.
Use .replace(), e.g.
function foo(i) {
if (i < 10) {
alert("bar");
}
}
document.write("<pre>"+foo.toString().replace("<","<")+"</pre>");
outputs:
function foo(i) {
if (i < 10) {
alert("bar");
}
}
本文标签: display javascript code in a html pageStack Overflow
版权声明:本文标题:display javascript code in a html page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120522a2421672.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论