个人的HTML入门文件

1次小小的实验

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My test page</title>
</head>
<body>
<style>

h1 {
font-size: 60px;
text-align: center;
margin: 0;
padding: 20px 0;
color: #9f7d00;
text-shadow: 3px 3px 1px blueviolet;}

p,li{
font-size: 16px;
line-height: 2;
letter-spacing: 1px;
}
a:hover{
color:red;
}

</style>
<h1>THIS IS THE TITLE</h1>
<button>Switch users</button>
<p>This is a paragragh shows the test website.</p>
<p>We got:</p>
<ol>
<li>Furries</li>
<li><strong>Hentaies/Perverts</strong></li>
<li>Homosexuals</li>
</ol>
<p>A link to my <a href="https://www.mozilla.org/" title="The Mozilla homepage" target="_blank">favorite website</a>.</p>
<p>
Let's touch our <strong>peanuts</strong> while browsering
<a href="https://benzi.yuwan.me/" title="鱼丸的本子站" target="_blank">this website</a>
to have a really satisfing jerking off!
</p>
<p>Click the image below to switch to another image.</p>
<img src="img/img1.png" alt="Images1" />
</body>
</html>

<script>
let myImage = document.querySelector('img');
myImage.onclick = function() {
let mySrc = myImage.getAttribute('src');
if(mySrc === 'img/img1.png') {
myImage.setAttribute('src', 'img/img2.png');
} else {
myImage.setAttribute('src', 'img/img1.png');
}
}

let myButton = document.querySelector('button');
let myHeading = document.querySelector('h1');

function setUserName();

if(!localStorage.getItem('name')) //如果初始没设置过名字
{
setUserName();
}
else //设置了
{
let storedName = localStorage.getItem('name');
myHeading.textContent = '你好,' + storedName;
}

function setUserName() //设置用户名字
{
let myName = prompt('请输入你的名字。');//myName变量是函数内变量,弹出输入的对话框
localStorage.setItem('name', myName);
if(!myName)
{alert('你没有输入任何字符!')}
else
{
alert('修改成功,现在你的名字是'+myName)
myHeading.textContent = '你好,' + myName;
}
}

myButton.onclick = function() {
setUserName();
}
</script>