非表单元素的属性

  • href、title、id、src、className
  • innerHTML和innerText
  • HTML转义符

" "
' '
& &
< &lt; // less than 小于
> &gt; // greater than 大于
空格 &nbsp;
© &copy;

  • innerHTML和innerText的区别
  • innerText的兼容性处理

    表单元素属性

  • value 用于大部分表单元素的内容获取(option除外)

  • type 可以获取input标签的类型(输入框或复选框等)
  • disabled 禁用属性
  • checked 复选框选中属性
  • selected 下拉菜单选中属性

    自定义属性操作

  • getAttribute() 获取标签行内属性

  • setAttribute() 设置标签行内属性
  • removeAttribute() 移除标签行内属性
  • 与element.属性的区别: 上述三个方法用于获取任意的行内属性。

    样式操作

  • 使用style方式设置的样式显示在标签行内

var box = document.getElementById('box');
box.style.width = '100px';
box.style.height = '100px';
box.style.backgroundColor = 'red';
注意
通过样式属性设置宽高、位置的属性类型是字符串,需要加上px

类名操作

  • 修改标签的className属性相当于直接修改标签的类名

var box = document.getElementById('box');
box.className = 'show';