`
qsxinyu
  • 浏览: 7358 次
  • 性别: Icon_minigender_1
  • 来自: 河南
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

document.getElementById的疑问

 
阅读更多

差别在哪里?

document.getElementById("operAtt").value="clientList";

 

document.forms[0].operAtt.value = "clientList";

 

第一句是根据ID值"operAtt",通过document.getElementById("operAtt")得到的元素对象,设置对象的属性值。(前提是该元素设置了ID属性)

 

为何第二句会有出错的时候?

第二句是第一个form表单中的属性"operAtt",设置其值。

 

第二句一般用在去form表单的属性,如:

document.forms[0].action
document.forms[0].name

 

<from action="" name="" />

 

中的name和action。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics