deng131 发表于 2013-2-7 00:58:35

DOM对象getAttribute()与getAttributeNode()

由于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
页: [1]
查看完整版本: DOM对象getAttribute()与getAttributeNode()