javascript innerText和innerHtml应用
作者:bea
看看代码 <head runat="server"> <title>无标题页</title> <script language="javascript"> function ok(){ var txt=new Array(); txt.push("<strong>"); txt.push("I am Strong"); txt.push("</strong>"); txt.push("I'm not s
看看代码
<head runat="server"> <title>无标题页</title> <script language="javascript"> function ok(){ var txt=new Array(); txt.push("<strong>"); txt.push("I am Strong"); txt.push("</strong>"); txt.push("I'm not strong") document.getElementById("adiv").innerHTML=txt.join(" ");//字符中的分隔符 txt=null;//释放内存提高性能 } </script></head><body onload="ok()"> <form id="form1" runat="server"> <div id="adiv"> </div> </form></body>
document.getElementById("adiv").innerHTML=txt.join(" ");
使用innerHtml会转义成HTML。加粗显示出来
使用innerText不会转译,标签全出来了
js中的 ok这个函数,就想c#里的StringBuilder,
js中用数组这种写法,可以提高字符串的性能!!!!
有用 | 无用
<head runat="server"> <title>无标题页</title> <script language="javascript"> function ok(){ var txt=new Array(); txt.push("<strong>"); txt.push("I am Strong"); txt.push("</strong>"); txt.push("I'm not strong") document.getElementById("adiv").innerHTML=txt.join(" ");//字符中的分隔符 txt=null;//释放内存提高性能 } </script></head><body onload="ok()"> <form id="form1" runat="server"> <div id="adiv"> </div> </form></body>
document.getElementById("adiv").innerHTML=txt.join(" ");
使用innerHtml会转义成HTML。加粗显示出来
使用innerText不会转译,标签全出来了
js中的 ok这个函数,就想c#里的StringBuilder,
js中用数组这种写法,可以提高字符串的性能!!!!
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jQuery生成asp.net服务器控件的代码
- js实现的仿Photoshop鼠标滚轮控制输入框取值(修正兼容Chrome)
- js中鼠标滚轮事件详解(firefox多浏览器)
- JavaScript面向对象之静态与非静态类
- JavaScript 学习笔记(十六) js事件
- js左侧多级菜单动态的解决方案
- javascript 三种编解码方式
- 对字符串进行HTML编码和解码的JavaScript函数
- javaScript 关闭浏览器 (不弹出提示框)
- javascript让setInteval里的函数参数中的this指向特定的对象
- 详细讲解JS节点知识
- javascript中的array数组使用技巧
- jquery 批量上传图片实现代码
- Jquery 常用方法经典总结
- javascript 匿名函数的理解(透彻版)
- JavaScript 学习笔记(十五)
- Extjs 几个方法的讨论
- JavaScript 判断判断某个对象是Object还是一个Array
- 图像替换新技术 状态域方法