通用参数 | 意义 |
---|---|
bgcolor = #ffffff | 背景颜色 |
style = "backgroundColor:#ffffff" | 设置样式,参见 样式 |
class = "myclass" | 设置样式类 |
name = "myname" 或 id = "myname" | 设置名称 |
onclick = "myfun()" | 设置单击事件,参见 事件 |
通用属性/方法 | 意义 |
---|---|
tagName | 取 HTML 标签 |
innerHTML | 包含 HTML 内容 |
innerText | 包含文本内容 |
className | 类名 |
parentElement | 父对象(容器) |
onclick | 事件脚本内容 |
appendChild(obj) | 附加子对象,一般生成方法 createElement("TAG") |
select() | 获得焦点并选中文本 |
focus() | 获得焦点 |
以下是三种根据鼠标位置更改背景色的方法:
<html> <style> .c1 { background-color : #ededed } .c2 { background-color : #cccccc } </style> <body> <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0> <tr><td style="CURSOR: hand" onmouseover="this.style.backgroundColor='#ededed'" onmouseout="this.style.backgroundColor='#CCCCCC'">DOM 文档方法</td></tr> <tr><td style="CURSOR: hand" onmouseover="this.bgColor='#ededed'" onmouseout="this.bgColor='#CCCCCC'">客户端 JavaScript 方法</td></tr> <tr><td id=ccc style="CURSOR: hand" class="noset" onmouseover="this.className='c1'" onmouseout="this.className='c2'">设置样式表方法</td></tr> </TABLE> </body> </html> |