JavaScript 操纵元素属性

来源:互联网 发布:投资白银如何看数据 编辑:程序博客网 时间:2024/05/16 04:52

元素属性操作
第一种:oDiv.style.display=“block”;
第二种:oDiv.style[“display”]=“block”;
第三种:Dom方式
DOM方式操作元素属性
获取:getAttribute(名称)
设置:setAttribute(名称, 值)
删除:removeAttribute(名称)

<!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><style></style><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript">window.onload=function (){    var oTxt=document.getElementById('txt1');    //1    //oTxt.value='123';    //2    //oTxt['value']='abc';    //3    //oTxt.setAttribute('value', 'rtertw');    alert(oTxt.getAttribute('id'));}</script></head><body><input type="text" id="txt1"/></body></html>

参考:JavaScript

原创粉丝点击