Exclusive attributes refer to those attributes that are exclusive to a certain tag. For example, the tag has href and target attributes. has the src attribute;
a_element.href Returns the hyperlink pointed to by the current node
Let’s take a look The more commonly used general method:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .form_style{ color: #5b5b5b; font-size: large; } p { color: #5b5b5b; font-size: larger; } </style> </head> <body> <form id='first_form' class="form_style" name="cangjingge" > 请选择功法:<br/> <input type="radio" name="gongfa" value="jysg">九阳神功<br/> <input type="radio" name="gongfa" value="qkdny">乾坤大挪移<br/> <input type="radio" name="gongfa" value="khbd">葵花宝典<br/> <input type="radio" name="gongfa" value="xxdf">吸星大法<br/> </form> <p>少侠请三思!!!</p> <script> //js演示代码请添加至此 </script> </body> </html>
1 element.appendChild(nodeName) Add a new child to the element node as the last child node and returns that child node. To add a new element to the HTML DOM, you must first create the element and then append it to an existing element.
js demo code:
##
var a=document.getElementById('first_form'); var textnode=document.createTextNode("慎重选择"); a.appendChild(textnode)
element.getAttribute(para) Returns the designation of the element node attribute value.
js demo code:##
var a=document.getElementById('first_form'); console.log(a.getAttribute('name')) //控制台输出name的值
element.getAttributeNode(para) Returns the specified attribute node . js demo code:
##var a=document.getElementById('first_form'); console.log(a.getAttributeNode('name')) //控制台输出name属性节点
4
Returns the specified tag name The collection of all child elements. js demo code:
var a=document.getElementById('first_form'); console.log(a.getElementsByTagName('input')) //控制台输出
5
If the element has the specified attribute , returns true, otherwise returns false. js demo code:
var a=document.getElementById('first_form'); console.log(a.hasAttribute('name')) //控制台输出
6
In the specified Insert new nodes before existing child nodes. js demo code:
var a=document.getElementById('first_form'); var inputList=document.getElementsByTagName('input'); var newNode=document.createElement('input'); var newNode2=document.createTextNode('天马流星拳'); var br=document.createElement('br'); newNode.type='radio'; newNode.name='gongfa'; newNode.value='tmlxq'; a.insertBefore(newNode,inputList[2]); a.insertBefore(newNode2,inputList[3]); a.insertBefore(br,inputList[3]);
7
Remove the specified element from the element Attributes. js sample code:
##
var a=document.getElementById('first_form'); a.removeAttribute('name'); console.log(a.hasAttribute('name'))
element.removeChild()
Remove the child from the element node. Although the removed node is no longer in the document tree, it is still in memory and can be referenced at any time. js sample code:
var a=document.getElementById('first_form'); a.removeChild(a.childNodes[3]);
element.replaceChild(newNode,replaceNode)
Replace the specified node Replace with new node. 10 element.setAttribute(attrName,attrValue)
Set or change the specified attribute to the specified value. js sample code:
##var a=document.getElementById('first_form'); a.setAttribute('name','shaolinsi'); console.log(a.name)
11
element.setAttributeNode()
js sample code:
var a=document.getElementById('first_form'); var attr = document.createAttribute('id'); attr.value='the_first'; a.setAttributeNode(attr); console.log(a.id)
12
nodelist.item()
js sample code:
var a=document.getElementsByTagName('input') console.log(a.item(2))
The above is the detailed content of Summary of exclusive attribute instances of javascript dom objects. For more information, please follow other related articles on the PHP Chinese website!