document.createElement()介绍与用法
来源:互联网 发布:实木家具品牌知乎 编辑:程序博客网 时间:2024/06/06 21:40
在以前的IE4中, document只能创建img, area, option三种元素, 到了IE5, 一般可以编程创建几乎所以元素, 除了frame和iframe. 而且这些新的创建的元素的属性都是可读写的, 并且可以编程随意访问. 但是你必须得先把他们先回到他们相应的集合中或者当前文档中你才能使用, 否则会报错. 添加新的元素到当前文档, 可以使用insertBefore或appendChild方法.
示例:
var option = document.createElement("option");
//注意顺序, 只能先加到options后才能使设置的属性显示出来.因为只有先加到options,元素option才能被初始化为
//option元素,且具有option的专有属性.
seleObj.options.add(option);
option.innerText = "北京";
option.value = "3";
如果是创建一个input元素, 则在调用createElement方法后, 必须紧跟着设置它的type.
另外, 属性可以写进createElement方法, 只要需要添加进去的元素的标签格式是合理的html格式, 如:
document.createElement ("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='Second'>");
另外还建议, 如果form表单是通过reset方法或button类型reset来重置, 则最好把form的属性就用上一行所用的方式写去createElement方法.这样可以方便, 更快的编程.
- document.createElement()介绍与用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement() 的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement() 用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- document.createElement()的用法
- 闲聊假币事件
- 回锅肉是怎样炼成的
- Document 文挡对象详解(JavaScript脚本语言描述)
- /etc启动运行脚本
- 网络中保证视频流的连续性、稳定性
- document.createElement()介绍与用法
- 使用pdb调试Python程序
- [经验总结]Google代码搜索很不错
- 我的爸爸
- FRAME 元素 | frame 对象
- Ruby的include和extend
- HTTP协议
- 在Ubuntu8.10下为PHP安装coreseek全文检索引擎支持的详细步骤
- static_cast” : 无法从“void (__thiscall CMainFrame::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCmdTarget::* )(NMHDR *,LRESULT