JSON
- JavaScript Object Notation 是一种轻量级数据交换格式
- 一切皆对象
- JSON.stringify()
- JSON.parse()
面向对象编程
let user ={
name:"user",
age:28,
run:function(){
return this.name + " running";
}
}
let xiaoming = {
name:"xiaoming"
}
xiaoming.__proto__ = user;
xiaoming.run();
function Student(name){
this.name = name
}
Student.prototype.run = function(){
return this.name + " running";
}
let wu = new Student("wu");
wu.run();
class Student{
constructor(name){
this.name = name;
}
run(){
return this.name + "running";
}
}
let wu = new Student("wu");
wu.run();
class Pupil extends Student{
construtor(name,grade){
super(name);
this.grade = grade;
}
play(){
return this.name + this.grade + "playing";
}
}
let li = new Pupli("li","first class");
li.play();
li.run();
- 原型链 __proto__ 每个构造函数都有一个原型对象,原型对象都包含一个指向构造函数的指针 而实例都包含一个指向原型对象的内部指针
操作BOM对象
- BOM(浏览器对象模型)
- window 代表 浏览器窗口 和 全局变量
window.innerHeight;
window.innerWidth;
window.outerHeight;
window.outerWidth;
window.navigator.appName;
navigator.appVersion;
screen.width;
screen.height;
location;
href:"https://www.baidu.com"
host:"www.baidu.com"
location.reload();
location.assign([url]);
document.title;
document.cookie;
history.back();
histoty.forward();
操作DOM对象
let h1 = document.getElementById("id1");
let p1 = document.getElementsByTagName("p");
let p2 = document.getElecmentsByClassName("cl1");
p1[0].innerText("新文本");
p1[0].innerHTML("<h1>新文本</h1>");
p1[0].style.color="red";
p1[0].style.fontSize="200px";
let father =p1[0].parentElement;
father.removeChild(p1[0]);
father.appendChild(p2);
let newDom = document.createElement("p");
newDom.id="addp";
newDom.setAttribute("id","addp");
newDom.innerText ="大家好" ;
father.appendChild(newDom);
father.insertBefore(newDom,p1[0]);
<form method="get" action="new_file.html" id="form1">
<label for="txt1">账户:</label><input type="text" id="txt1" name="txt1" placeholder="输入账户名" required/>
<input type="submit" name="submit1" value="提交" />
<input type="radio" name="gender" value="man">男
<input type="radio" name="gender" value ="woman" checked>女
</form>
let form1 = document.getElementById("form1");
form1[0].value;
form1[2].checked;
<form method="post" action="https://www.baidu.com" id="form1">
<label for="txt1">账户:</label><input type="text" id="txt1" name="user" placeholder="输入账户名"
required />
<span>密码</span><input type="password" placeholder="输入密码" requird/>
<input type="hidden" name="password" id="md5pasd" />
<!-- <input type="submit" name="submit1" onclick="my()" value="提交吧犊子" /> -->
<input type="radio" name="gender" value="男" />男
<input type="radio" name="gender" value="女" checked="女"/>女
<button type="submit" onclick="my()" >提交大</button>
</form>
<script>
function my(){
let pass = document.getElementById("txt1");
let mdpass = document.getElementById("md5pasd");
console.log(pass.value);
mdpass.value = md5(pass.value);
console.log(mdpass.value);
return true;
}
JQuery
$(document).ready(function(){
})
==
$(function(){
})
<span id="sp" style="color: #FF0000;"></span>
<div id="dv" style="width: 300px;height: 400px;border: 2px solid #000;"></div>
$(function(){
$("#dv").mousemove(
function(e){
$("#sp").text("x:" + e.pageX + " y:" + e.pageY);
})
})
<div id="test">
<li class="li1">JavaScript</li>
<li name="li2">Python</li>
</div>
$("#test .li").text("Java");
$("#test li[name=li2]").toggle();
$("#test .li").css({"color":"red","backgrond":"black","fontSize":"20px"});