Skip to content

Commit bddf18b

Browse files
committed
demo
practice demo
1 parent 3257999 commit bddf18b

14 files changed

Lines changed: 448 additions & 0 deletions

‎demo/DOM.html‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<p>Hello Word</p>
9+
<div id="main">
10+
<p>The Dom is very useful,this is getElementById</p>
11+
<p>本例演示<b>getElementByTagName</b></p>
12+
<p class="methos">这是getElementByClassName</p>
13+
</div>
14+
<hr>
15+
<div id="one">
16+
<p>this is test text,to get change THML content,</p>
17+
</div>
18+
<hr>
19+
<div id="two">
20+
<p>This is test text,to get getElementByTagName()</p>
21+
</div>
22+
<hr>
23+
<div id="three">
24+
<h1 id="H">原来内容</h1>
25+
<button type="butotn" onclick="document.getElementById('H').style.color='red'">按钮</button>
26+
</div>
27+
<hr>
28+
<div id="four">
29+
<p id="visi">这是一段文本</p>
30+
<input type="button" value="隐藏文本" onclick="document.getElementById('visi').style.visibility='hidden'">;
31+
<input type="button" value="显示文本" onclick="document.getElementById('visi').style.visibility='visible'">;
32+
</div>
33+
<hr>
34+
<div id="five">
35+
<p onclick="this.innerHTML='谢谢!'">点击p标签上的元素会改变文本的内容</p>
36+
</div>
37+
<hr>
38+
<div id="six">
39+
<script>
40+
function changetext(id){
41+
id.innerHTML="函数!";
42+
}
43+
</script>
44+
<p onclick="changetext(this)">点击改变文本内容,函数</p>
45+
</div>
46+
<hr>
47+
<div id="seven">
48+
<p>点击按钮就可以改变displayDate()函数</p>
49+
<button onclick="displayDate()">点击这里</button>
50+
<script>
51+
function displayDate(){
52+
document.getElementById("demo").innerHTML=Date();
53+
}
54+
</script>
55+
<p id="demo"></p>
56+
</div>
57+
<hr>
58+
<!-- <div id="eight">
59+
<p>点击按钮时可以执行<em>displayDate()</em>函数</p>
60+
<button id="myBtn">点击这里</button>
61+
<script>
62+
document.getElementById("myBtn").onclick()=function()
63+
{
64+
displayDate()
65+
};
66+
function displayDate(){
67+
document.getElementById('demo2').innerHTML=Date();
68+
}
69+
</script>
70+
<p id="demo2"></p>
71+
</div>
72+
</body> -->
73+
</html>
74+
<script>
75+
/*
76+
DOM简介:
77+
JavaScript能够改变页面中所有的HTML元素,
78+
{
79+
通过id(getElementById)
80+
标签名(getElementByTagName)
81+
类名(getElementByClassName)
82+
}
83+
JavaScript能够改变页面中的所有HTML属性
84+
JavaScript能够改变页面中的所有CSS样式
85+
JavaScript能够对页面中的所有时间做出反应。
86+
87+
1.改变HTML输出流
88+
document.write();
89+
2.改变HTML内容
90+
document.getElementById(id).innerHTML=new HTML
91+
3.改变HTML属性
92+
document.getElementById(id).attribute=new value;
93+
4.改变HTML样式
94+
document。getElementById(id).style.attribute=value;
95+
*/
96+
/*
97+
var x=document.getElementById("main");
98+
var y=x.getElementsByClassName("methos");
99+
document.write('类名为"methos"的p标签中的文本是:'+y[1].innerHTML);
100+
101+
var a=document.getElementById("two");
102+
var b=a.getElementsByTagName("p");
103+
document.write('id为"two"的div中的第一段文本是:'+y[0].innerHTML);
104+
105+
document.getElementById("mian").innerHTML="改变THML的内容"
106+
*/
107+
document.getElementById("main").style.fontFamily="Arial";
108+
document.getElementById("one").style.color="red";
109+
document.getElementById("two").style.fontSize="larger";
110+
111+
112+
</script>

‎demo/cookie.html‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body onload="checkCookies()">
8+
<script>
9+
function checkCookies(){
10+
if (navigator.cookieEnabled==true)
11+
{
12+
alert("已启用cookie")
13+
}
14+
else
15+
{
16+
alert("未启用cookie")
17+
}
18+
}
19+
</script>
20+
<p>提示框会告诉你,浏览器是否已启用cookies</p>
21+
</body>
22+
</html>

‎demo/for in.html‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<P>点击下面的按钮,循环遍历对象"person"的属性</P>
9+
<button onclick="myFunction()">点击这里</button>
10+
<p id="demo"></p>
11+
<script>
12+
function myFunction(){
13+
var x;
14+
var txt="";
15+
var person={fname:"Bill",lname:"Gates",age:56};
16+
17+
for(x in person){
18+
txt=txt+person[x];
19+
}
20+
document.getElementById("demo").innerHTML=txt;
21+
}
22+
</script>
23+
</body>
24+
</html>

‎demo/mouseover&mouseout.html‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<style>
7+
#main{
8+
background-color: green;
9+
width: 120px;
10+
height: 20px;
11+
padding: 40px;
12+
color: #ff00ff
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<div id="main" onmouseover="mOver(this)" onmouseout="mOut(this)">
18+
把鼠标移动到是上面
19+
</div>
20+
<script>
21+
function mOver(obj){
22+
obj.innerHTML="谢谢"
23+
}
24+
25+
function mOut(obj){
26+
obj.innerHTML="把鼠标移动到上面"
27+
}
28+
</script>
29+
</body>
30+
</html>

‎demo/onchange.html‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<script>
7+
function myFunction(){
8+
var x=document.getElementById('fname');
9+
x.value=x.value.toUpperCase();
10+
}
11+
</script>
12+
</head>
13+
<body>
14+
请输入英文字符:<input type="text" id="fname" onchange="myFunction()">
15+
<p>当你离开输入字段时,会触发将输入文本转换为大写的函数</p>
16+
</body>
17+
</html>

‎demo/onmousedown&onmouseup.html‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<style>
7+
#main{
8+
background-color: green;
9+
width: 90px;
10+
height: 20px;
11+
padding: 40px;
12+
font-size: 12px;
13+
color: #ffff00;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div id="main" onmousedown="mDown(this)" onmouseup="mUp(this)">
19+
请点击这里
20+
</div>
21+
<script>
22+
function mDown(obj){
23+
obj.style.backgroundColor ="#0000ff";
24+
obj.innerHTML="请释放鼠标按钮"
25+
}
26+
function mUp(obj){
27+
obj.style.backgroundColor = "#00ff00";
28+
obj.innerHTML="请按下鼠标按钮"
29+
}
30+
</script>
31+
</body>
32+
</html>

‎demo/xunhuan.html‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<script>
9+
var bb=[1,2,3,4,5],[1,3,5,6],[2,4,6]];
10+
for(var i=0;i<bb.length;i++){
11+
console.log(bb[i],i);
12+
for (var j=0;j<bb[i].length;j++) {
13+
console.log(bb[i][j],j)
14+
}
15+
16+
}
17+
</script>
18+
</body>
19+
</html>

‎demo/函数.html‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<p>点击按钮可以执行displayDate()函数</p>
9+
<button id="myBtn">点击这里</button>
10+
<script>
11+
document.getElementById('myBtn').onclick=function(){
12+
displayDate()
13+
};
14+
function displayDate(){
15+
document.getElementById('demo').innerHTML=Date();
16+
}
17+
</script>
18+
<p id="demo"></p>
19+
</body>
20+
</html>

‎demo/创建JavaScript对象.html‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<!--
9+
1.创建对象的方法
10+
(1).直接创建 person=new Object();
11+
(2).字面量literals {逗号隔开}
12+
(3).使用对象构造器
13+
14+
-->
15+
<script>
16+
/*
17+
直接创建
18+
person=new Objdect();
19+
person.firstname="Bill";
20+
person.lastname="Gates";
21+
person.age=23;
22+
person.eyecolor="blue";
23+
*/
24+
25+
/*字面量创建
26+
person1={
27+
firstname:"Bill",
28+
lastname:"gates",
29+
age:56,
30+
eyecolor:"blue"
31+
}
32+
document.write(person1.firstname+" is "+person1.age+" years old")
33+
*/
34+
/*
35+
对象构造器
36+
*/
37+
function person(firstname,lastname,age,eyecolor){
38+
this.firstname=firstname;
39+
this.lastname=lastname;
40+
this.age=age;
41+
this.eyecolor=eyecolor;
42+
}
43+
myFather=new person("Bill","Gates",56,"blue");
44+
document.write(myFather.firstname+" is "+myFather.age+" years old");
45+
</script>
46+
</body>
47+
</html>

‎demo/创建新的HTML元素.html‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<div id="div1">
9+
<p id="p1">这是第一个段落</p>
10+
<p id="p2">这是第二个段落</p>
11+
</div>
12+
<script>
13+
var para=document.createElement("p");
14+
var node=document.createTextNode("这是新段落");
15+
para.appendChild(node);
16+
17+
var element=document.getElementById('div1');
18+
element.appendChild(para);
19+
</script>
20+
<!--
21+
1.创建新的p元素createElement()
22+
2.创建文本节点createTextNode()
23+
3.添加节点到p元素 para.appendChild(node);
24+
4.向一个已有的元素添加新元素 element.appendChild(para);
25+
-->
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)