2.定时器相关
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<h1>0h1>
<h2>0h2>
<script>
setInterval(f,1000);
let count=0;
let h1 = document.querySelector("h1");
function f() {
count++;
h1.innerText=count;
}
let timer=setInterval(function () {
console.log(count);
if(count==5){
clearInterval(timer);
}
},100)
setTimeout(function () {
let h2 = document.querySelector("h2");
h2.innerText="时间到!";
},3000)
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
3.页面相关
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<input type="text">
<input type="button" value="按钮"onclick="f()">
<script>
function f() {
let i = document.querySelector("input");
let h1 = document.createElement("h1");
h1.innerText=i.value;
document.body.append(h1);
let img = document.createElement("img");
img.src="../imgs/a.jpg";
document.body.append(img);
}
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
4.图片练习
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<input type="text" placeholder="请输入添加图片的数量" id="i1">
<input type="button" value="帅哥" onclick="f(1)">
<input type="button" value="美女" onclick="f(2)">
<hr>
<script>
function f(x){
let imgName=x==1?"../imgs/a.jpg":"../imgs/b.jpg";
let i1 = document.querySelector("#i1");
for(let i=0;i<i1.value;i++){
let img = document.createElement("img");
img.src=imgName;
img.width=100;
document.body.append(img);
}
}
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
5.员工列表练习
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<input type="text" placeholder="员工姓名" id="i1">
<input type="text" placeholder="员工工资" id="i2">
<input type="text" placeholder="员工工作" id="i3">
<input type="button" value="添加" onclick="f()">
<table border="1">
<caption>员工列表caption>
<tr>
<th>姓名th>
<th>工资th>
<th>工作th>
tr>
table>
<script>
function f() {
let tr = document.createElement("tr");
let nameTd = document.createElement("td");
let salaryTd = document.createElement("td");
let jobTd = document.createElement("td");
nameTd.innerText=i1.value;
salaryTd.innerText=i2.value;
jobTd.innerText=i3.value;
tr.append(nameTd,salaryTd,jobTd);
let table = document.querySelector("table");
table.append(tr);
}
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
6.自定义对象
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<table border="1">
<caption>商品列表caption>
<tr>
<th>商品标题th>
<th>商品价格th>
<th>商品销量th>
tr>
table>
<script>
let p1={};
p1.name="张三";
p1.age=20;
p1.run=function () {
console.log(this.name+":"+this.age);
}
p1.run();
let p2={
name:"李四",
age:18,
run:function () {
console.log(this.name+":"+this.age);
}
}
p2.run();
let arr=[{title:"小米手机",price:4000,saleCount:200},
{title: "李宁篮球鞋",price: 500,saleCount: 1200},
{title: "统一方便面",price: 5,saleCount: 300}]
for (let product of arr){
let tr = document.createElement("tr");
let titleTd = document.createElement("td");
let priceTd = document.createElement("td");
let saleCountTd = document.createElement("td");
titleTd.innerText=product.title;
priceTd.innerText=product.price;
saleCountTd.innerText=product.saleCount;
tr.append(titleTd,priceTd,saleCountTd);
let table=document.querySelector("table");
table.append(tr);
}
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
7.综合练习
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<table border="1">
<caption>个人信息caption>
<tr>
<td>照片:td>
<td id="head_td">td>
tr>
<tr>
<td>名字:td>
<td id="name_td">td>
tr>
<tr>
<td>年龄:td>
<td id="age_td">td>
tr>
<tr>
<td>好友:td>
<td id="friend_td">td>
tr>
table>
<input type="button" value="请求数据" onclick="f()">
<script>
function f() {
let person={url:"../imgs/a.jpg",name:"苍老师",age:18,friend:["克晶姐","传奇哥","我"]}
name_td.innerText=person.name;
age_td.innerText=person.age;
let img = document.createElement("img");
img.src=person.url;
img.width=100;
head_td.append(img);
let ul = document.createElement("ul");
for(let name of person.friend){
let li = document.createElement("li");
li.innerText=name;
ul.append(li);
}
friend_td.append(ul);
}
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
8 HelloVueCDN和本地
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<div>
<h1>{{info}}h1>
div>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js">script>
<script>
let v=new Vue({
el:"body>div",
data:{
info:"Hello Vue!"
}
})
setTimeout(function () {
v.info="值变了!"
},3000)
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
9.文本相关指令
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<div>
{{msg}}
<p>{{msg}}p>
<h1>{{msg}}h1>
<h1 v-text="msg">h1>
<p v-html="msg">p>
div>
<script src="js/vue.min.js">script>
<script>
new Vue({
el:"body>div",
data:{
msg:"文本相关文本相关>"
}
})
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
10.属性绑定
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<div>
<a :href="url">超链接1a>
<a v-bind:href="url">超链接2a>
<img :src="imgName" alt="">
<input type="text" :value="info">
div>
<script src="js/vue.min.js">script>
<script>
let v=new Vue({
el:"body>div",
data:{
url:"http://www.baidu.com",
imgName:"../imgs/a.jpg",
info:"属性绑定"
}
})
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28