JSON.stringify()講對象轉化爲字符串javascript
JSON.parse()解析字符串變爲對象css
JavaScript,Java,c# 面向對象html
JavaScript有些區別java
類:模板編程
對象:具體實例json
在JavaScript這個須要換一下思惟方式c#
原型:__ proto __數組
ES6有class,和java同樣 本質是原型瀏覽器
瀏覽器的介紹app
JavaScript和瀏覽器的關係?
JavaScript誕生就是爲了讓他在瀏覽器中運行
BOM:瀏覽器對象模型
三方
能夠安裝內核
window
window表明瀏覽器窗口
Navigator
Navigator 封裝了瀏覽器的信息
screen
表明屏幕尺寸
location
location表明當前頁面的URL信息
history
history.back()//後退
history.forward()//前進
DOM:文檔對象模型
核心
<div id="father"> <h1>標題1</h1> <p id="p1">p1</p> <p class="p2">p2</p> </div> <script> //對應選擇器 var h1 = document.getElementsByTagName('h1'); var p1 = document.getElementById('p1'); var p2 = document.getElementsByClassName('p2'); var father = document.getElementById('father'); var childs = father.children;//獲取父節點的全部子節點 </script>
var p1 = document.getElementById('p1'); p1.innerText="123"; p1.innerHTML='<strong>123</strong>'; p1.style.color='yellow';
先獲取父節點,再刪除本身
var self = document.getElementById('p1'); var father = p1.parentElement; father.removeChild(self)
var list = document.getElementById('p1'); list.appendChild(js) insertBefore(newNode,TargetNode)
var NP = document.CreateElement('p'); NP.id = 'NP1';//或者 NP.setAttribute('id','NP1'); NP.innerText="123"; list.appendChild(NP)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script> </head> <body> <form action="https://www.baidu.com/" method="post" id="user" onsubmit="return aaa()"> <p> <span>用戶名:</span><input type="text" id="username" name="username"> </p> <p> <span>密碼:</span><input type="password" id="password"> </p> <input type="hidden" id="md5-password" name="password"> <button type="submit">提交</button> </form> <script> function aaa() { alert(1); var username = document.getElementById('username'); var pwd = document.getElementById('password'); var mpwd = document.getElementById('md5-password'); mpwd.value=md5(pwd.value); return true; } </script> </body> </html>