JavaScript Base

window.innerWidth
window.innerHeight
window.screen.availWidth
window.screen.availHeigh
window.screen.width
window.screen.height

Code:

elementList = parentNode.querySelectorAll(selectors);

elementList.forEach(function(element) {
    console.log(element)
});

Element Property:

ParentNode.childElementCount

ParentNode.firstElementChild

ParentNode.lastElementChild

ParentNode.children

Element.tagName

Code:

const div = document.createElement('div')
div.className = "big"
div.innerHTML = "Hello World!"
div.style = "color: green;"
console.log(div.outerHTML)
document.body.appendChild(div)

let loop
loop = setInterval(() => {
    div.classList.toggle("big")
}, 1000)

let bt = document.createElement("button")
bt.className = "bt"
bt.innerHTML = "Stop Color Toggle"
document.body.appendChild(bt)

let stopinterval = function() {
    clearInterval(loop);
}
document.querySelector(".bt").addEventListener("click", stopinterval)

JavaScript

这篇文章: 有用 无用
创建 2018-11-13 09:51:58 / 更新 2018-12-04 02:14:02

JavaScript 方法[1]

encodeURIComponent # 对连接进行escape

JSON.stringify()

JavaScript

这篇文章: 有用 无用
创建 2016-12-14 14:25:27 / 更新 2018-04-20 08:49:17

JavaScript DOM 学习[2]

document.title
document.baseURI    
document.URL
document.documentURI
document.referrer
document.domain

document.body                  # Returns the <body> element
document.documentElement           # Returns the <html> element
document.cookie

document.scripts                   # Returns all <script> elements
document.forms
document.links                     # Returns all <area> and <a> elements that have a href attribute

CODEPEN

document.URL

document.documentURI


JavaScript

这篇文章: 有用 无用
创建 2016-10-27 10:37:49 / 更新 2018-12-04 02:53:05

JavaScript DOM 学习[1]

http://www.w3schools.com/js/js_htmldom.asp

# DOM(Document Object Model)

# The document object represents your web page.

# If you want to access any element in an HTML page, you always start with accessing the document object.

# The innerHTML property can be used to get or change any HTML element, including <html> and <body>.

# document.getElementById(id)
# document.getElementsByTagName(name)
# document.getElementsByClassName(name)

# element.innerHTML =  new html content
# element.attribute = new value
# element.setAttribute(attribute, value)
# element.style = new style

<html>
<body>

<p id="demo">Hi</p>

<script>
alert(document.getElementById("demo").innerHTML);
document.getElementById("demo").innerHTML = "Hello World!";
</script>

</body>
</html>

JavaScript

这篇文章: 有用 无用
创建 2016-10-27 02:01:56 / 更新 2018-04-20 08:49:17

JavaScript 如何正则表达式

获得匹配值

var myString = "something format_abc";
var myRegexp = /format_(.+)/;
var match = myRegexp.exec(myString);
if (match != null) {
    console.log(match[1]); // abc
}

// simple code
var match = /format_(.+)/.exec("something format_abc");
if (match != null) {
    console.log(match[1]); // abc
}

测试是否匹配

var digital = new RegExp('[1-9]+');
let str = "1234";
if (digital.test(str)) {
    console.log("match");
}

// simple code
if ( /[1-9]+/.test("123") ) {
    console.log("match");
}

JavaScript

这篇文章: 有用 无用
创建 2016-10-26 11:17:41 / 更新 2018-11-16 09:10:58