js: DOM and its operation 2

Event three elements

  • Trigger element (are) event: Event Source
  • Event Type: trigger events (such as mouse clicks or keyboard clicks)
  • Event handlers: event-triggered code to be executed (functional form)

The basic use of events

Box document.getElementById = var ( 'Box'); 
box.onclick = function () {
 the console.log ( 'code is executed in the click Box');  
};
 

In the event of an element in their events this is the current element object

Property operations

Non-form element properties

Core DOM: API can operate everything

For example:

var alink = document.getElementById ( "ALINK");

Gets the property value:

alink.getAttribute(“href”);

Modify property value:

alink.setAttribute(“href”,”baidu.com”);

Comprising determining whether the specified attribute value (attribute definition in the html tag)

Var bool = alink.hasAttribute(“target”);

Remove property values

alink.removeAttribute(“title”);

HTML DOM: the core DOM API to simplify frequently used

Gets the property value:

alink.href;

Modify property value:

aLink.href = “baidu.com”;

Determine whether the properties contain

bool was aLink.target = = = "";

Removing property

aLink.title = “”;

This property is all the css writing multiple words, DOM operation in js code when the - removed, after the word to upper case

Form elements

  • Most form elements value for content acquisition (excluding option)
    • type type may acquire (input boxes or check boxes, etc.) INPUT tag
    • disabled disabled property
    • checked checkbox properties
    • selected drop-down menu select Properties

Law: In the form tag, and if the property value is only one, and this is the value of the property itself, then the time to write js code DOM operations, the value of this attribute is a Boolean type on it

As checked selected disabled (disabled) property redonly text field (read-only get, can not be modified)

Guess you like

Origin www.cnblogs.com/yqycr7/p/11389585.html