ITeye博客

DOM对象getAttribute()与getAttributeNode()

deng131 · 2010-12-16 12:23 · javascript · Web前端 · Markdown

由于form元素访问form表单对象中的子元素,可使用 document.form.inputName方式逐级访问表单元素。但是当form上name属性值为"verify"时候,如果通过上面方法当我需要取form的name属性时候那么去到取得到是将input对象。


<form name="verify">
  <input type="text" name="verify"/>
</form>

那么就需要用下面方法取得属性值以避免这种问题: 获取属性值 - getAttribute() getAttribute("") 方法返回属性的值。

获取属性值 - getAttributeNode() getAttributeNode("") 方法返回属性节点,getAttributeNode('').value取得节点值。 两种方法区别是一个返回属性值,后者返回属性节点。

参考: http://www.veryide.com/archive.php?id=59 http://qiqicartoon.com/?p=273 http://www.howtocreate.co.uk/tutorials/javascript/dombasics

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。