t.innerHTML=t.innerHTML.replace(/(if|else)/ig,'<font>$1</font>')
把用户输入的内容用下面的函数进行HTML编码后再显示到页面上就行了:
// HTML转义函数function encodeHtml(s){
return s.replace(
/"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g,
function($0){
var c = $0.charCodeAt(0)
switch(c){
case 13: return "<br />"
case 32: return "&#160"
default: return "&#"+c+""
}
}
)
}
我已经测试过了
new 会创建 pre 的对象, 但是没有 new 的话就没有没有可返回的值或对象了,所以是 undefined。 如果不想new 新的对象的话,可以在 pre 的方法里 返回一个值或对象。 function pre(){ this.radius = Math.random()return this.radius}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)