JS operation tag values, attributes, styles.

Acquiring first operation DOM node other elements or tags:

document.getElementById('id');

The input operation of the form:

Get the value of var users = document.getElementById ( 'user') value.;

赋值users=document.getElementById('user').value='abcdefg'

Replace non-form using innerHTML value:

innerHTML: returns html content within the tag, contains html tags

var dicy.innerHTML = "This is a new form of non-value";
the innerText: Returns a text value
(will be acquired <span> Text through innerHTML </ span> tag, innerText obtained only text)
operation attribute properties

get the value, set to set, remove delete
attribute ( 'property values')
getAttribute ( 'attribute name')

<a href="" target="" value="this is link" id="">

var aaa=document.getElementById('id')

aaa.getAttribute aaaGet = var ( 'Targe')
var aaaSet aaa.setAttribute = ( 'target', '_ blank')
var aaaRemove aaa.removeAttribute = ( 'attribute name')

operating style style:
. .style style name label objects ( Get the value of the style name)
label objects .style. style name = "value of the style '

var aaaColor=aaa.style.backgroundColor;

var aaaSetColor=aaa.style.backgroundColor="red";

Guess you like

Origin www.cnblogs.com/god3064371/p/11371741.html