【DOM编程艺术】动态创建标签
2014-04-15 11:26
197 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>动态创建标记</title> </head> <body> <script> window.onload=function(){ var testdiv=document.getElementById('testdiv'); var para=document.createElement('p'); var txt1=document.createTextNode('This is '); para.appendChild(txt1); var emphasis=document.createElement('em'); var txt2=document.createTextNode('my '); emphasis.appendChild(txt2); para.appendChild(emphasis); var txt3=document.createTextNode('content.'); para.appendChild(txt3); testdiv.appendChild(para); //Javascript代码执行后,testdiv里会插入一元素 <div id='testdiv'><p>This is <em>my</em> content.</p></div> } </script> <div id='testdiv'></div> </body> </html>
另一种方案就是先创建所有的节点,然后再把它们连接在一起。
相关文章推荐
- 动态创建标记(js dom编程艺术之第七章笔记)
- 【DOM编程艺术】动态创建标记(签)---创建和插入节点
- JS编程艺术笔记(3)-动态创建标记
- JavaScript DOM编程基础精华02(window对象的属性,事件中的this,动态创建DOM,innerText和innerHTML)
- JavaScript DOM编程基础精华02(window对象的属性,事件中的this,动态创建DOM,innerText和innerHTML)
- 使用DOM动态创建标签
- js-dom-动态创建html标签时,name属性的初始化问题
- 网站前端_JavaScript-DOM编程.0003.JavaScriptDom动态创建?
- JS DOM编程艺术——动态创建标记—— JS学习笔记2015-7-13(第83天)
- 基于dom编程中 动态创建与删除元素的使用
- 使用js改变DOM样式的三种方式 - 动态创建style标签
- 基于dom编程中 动态创建与删除元素的使用
- Javascript DOM 编程艺术:创建一个简单的gallery
- dom编程-动态创建、删除元素
- Dom7(动态创建标签,获取页面元素)
- 轻松学习JavaScript二十六:DOM编程学习之动态添加JS脚本和CSS样式
- 动态创建script标签实现跨域资源访问的方法
- 黑马程序员_学习日记60_706Dom2(事件冒泡、this、动态创建Dom、innerHTML、动态设置样式)
- 使用JavaScript和DOM动态创建表格(2)
- 动态创建标签