TML,即超文本标记语言(HyperText Markup Language),是构建网页和网络应用的基石。自从它的诞生以来,HTML经历了多次迭代,每个版本都对Web开发的可能性进行了扩展。以下是HTML发展历程的概述,包括每个主要版本的变化和未来趋势。
HTML的历史可以追溯到1989年,当时**蒂姆·伯纳斯-李(Tim Berners-Lee)**在CERN(欧洲核子研究组织)提出了一个创新的想法,即创建一个互联的信息系统,这个系统后来演变成了万维网(World Wide Web)。HTML是这个系统的核心组成部分,它允许文档通过超链接互相引用,形成一个信息网络。
随着Web技术的不断发展,HTML也在不断进化。未来的HTML可能会包括:
HTML的历史是Web技术发展的缩影。从简单的文档标记到复杂的Web应用平台,HTML已经成为现代互联网不可或缺的一部分。随着技术的进步,我们可以期待HTML将继续演进,以满足未来网络世界的需求。
喽,大家好,我是雷工。
今天学习JavaScript基础知识的分支语句,以下为学习笔记。
○写几句就从上往下执行几句,这种叫做顺序结构;
○有时要根据条件选择执行代码,这种叫分支结构;
○某段代码被重复执行,就叫循环结构;
○分支语句可以让我们有选择性的执行想要执行的代码
○分支语句包含:
→ if分支语句
→ 三元运算符
→ switch语句
2.1、if分支语句
● if语句有三种使用:单分支、双分支、多分支
● 单条件分支语句:程序如果执行的时候,如果条件成立就执行某一行代码,如果条件不成立则执行其他代码
使用语法:
if(条件)
{
满足条件要执行的代码
}
▶ 小括号内的条件为true时,进入大括号里执行代码。
▶ 小括号内的结果若不是布尔类型时,会发生隐式转换转换为布尔类型。
▶ 如果大括号内只有一个语句,大括号可以省略,但是,一般不提倡这么做~
● 双分支if语法:
if(条件)
{
满足条件要执行的代码
}
else
{
不满足条件时要执行的代码
}
语法解释:
1>程序先判断if中的条件是否成立(true),如果条件成立,则执行if后面对应的代码,else中的代码不会执行。
2>如果if中的条件不成立(False),程序只执行else后{}中的代码,if后{}内的代码不会执行。
● 多条件分支语句if:
应用场景:当有多个结果的时候,比如学习成绩可以分为:优秀、良好、及格、不及格四个选项。
语法:
if(条件1)
{
满足条件1要执行的代码1
}
else if(条件2)
{
满足条件2要执行的代码2
}
else if(条件3)
{
满足条件3要执行的代码3
}
else
{
以上条件均不满足时执行代码n
}
语法说明:
▶ 先判断条件1,若满足条件1就执行代码1,其他代码统统不执行;
▶ 若不满足则按顺序向下判断条件2,满足条件2执行代码2,其他代码不执行;
▶ 若依然不满足继续往下判断,依次类推 ;
▶ 若以上条件都不满足,执行else里的代码n ;
▶ 注:可以根据实际需要写N个条件,但这里演示只写2个;
单条件分支语句和多条件分支语句总结:
a)不管是单条件分支语句,还是多条件分支语句,else都可以省略(前提else中没有代码)
b)条件分支语句,如果只有一行代码,则{}可以省略。
例:if(3>0)alert("雷工笔记");
c)分支语句可以相互嵌套。
2.2、三元表达式
就是单条件分支语句的另外一种写法
语法:
条件 ? 代码1 : 代码2;
语法说明:
a)判断条件的真假,如果为真,则执行代码1,后面的代码2不执行;
b)如果条件不成立,则执行代码2,前面的代码1不执行;
● 一般用来取值
2.3、switch分支语句
switch 分支语句就是多条件分支语句的另外一种写法
语法:
switch(数据/变量)
{
case 值1:
代码1;
break;
case 值2:
代码2;
break;
case 值3:
代码3;
break;
default:
代码n;
break;
}
释义:
▶ 找到跟小括号里数据/变量全等的case值,并执行里面对应的代码
▶ 若没有全等 === 的则执行 default里面的代码
▶ 例:数据若跟值1全等,则执行代码1
注意事项:
1>. switch case语句一般用于等值判断,不适合于区间判断;
2>. switch case一般需要配合break关键字使用 没有break会造成case穿透(default后面的break可以省略);
3>.什么情况下使用switch语法?什么情况下使用多条件分支if语句?
a)在任何情况下都可以使用switch语句或者多条件分支语句;
b)如果变量的值是某些固定的值,推荐使用switch;
示例1:一年有12个月,1月-12月;
示例2:一年有4个季节,春,夏,秋,冬
c)如果变量的值是一个范围,推荐使用if多分支语句
示例:
1,现在my-pro项目下,新建若干用于测试的分支。
git checkout master #将HEAD指向master分支
git branch testdel #在master分之下新建分支
git checkout testdel #将HEAD指向testdel分支
#在这里修改一下style.css,例如加一个背景色background:#d8d8d8
git commit css/style.css -m'just a test commit' #在testdel分之下执行一个commit操作
git branch testagain
git checkout master
git branch anothertest
gitk --all #使用gitk可视化查看当前分支状况
经过多次分支新建及commit操作之后,我们的分支变成了如下图的结构:
2,使用git branch -d 【分支名称】命令,删除某个指定分支。
Yooye-2:my-pro yooye$ git branch -av #查看当前分支状态
anothertest dc7ecf7 let index.html link the style file
change-border-color 413552e change the box border-color
* master dc7ecf7 let index.html link the style file
testagain e1e471a just a test
testdel e1e471a just a test
Yooye-2:my-pro yooye$ git checkout master #进入master分支
Switched to branch 'master'
Yooye-2:my-pro yooye$ git branch -d testagain #使用-d删除某个分支
error: The branch 'testagain' is not fully merged.
If you are sure you want to delete it, run 'git branch -D testagain'. #提示我们使用-D进行删除
Yooye-2:my-pro yooye$ git branch -D testagain #使用-D再次尝试删除某个分支
Deleted branch testagain (was e1e471a). #删除成功
Yooye-2:my-pro yooye$ gitk --all #查看删除后的可视化分支状态
删除testagain分之后的状态如下:
3,当我们使用git checkout在testdel与master分支间切换的时候,项目中的style.css等代码文件,会随之切换。如果删除testdel分支,则在该分支下提交的所有commit操作记录将全被移除。所以我们在删除分支的之前一定要做版本确认。
使用 git commit --amend命令,修改最近一次提交的commit的描述性文字。操作流程如下:
Yooye-2:my-pro yooye$ git checkout testdel #【1】进入testdel分支
Switched to branch 'testdel'
Yooye-2:my-pro yooye$ git log -1 #【2】查看最近一次的提交记录,注意这里是git log -[数字1]
commit e1e471a5945ab83673bc56055e3455e9fbec8e61 (HEAD -> testdel)
Author: 卢大湿 <dashi@vip.com>
Date: Fri Mar 1 10:26:49 2019 +0800
just a test # 【2-1】这是修改之前的描述文字
Yooye-2:my-pro yooye$ git commit --amend # 【3】执行修改命令,进入修改状态,详细操作看下面第【4】步
Yooye-2:my-pro yooye$ git log -1 #【5】查看确定是否修改成功
commit 1062fa43b85ad7111738d4eaee56436279768757 (HEAD -> testdel)
Author: 卢大湿 <dashi@vip.com>
Date: Fri Mar 1 10:26:49 2019 +0800
just a test and i had change this words 【5-1】修改后的描述文字
Yooye-2:my-pro yooye$
【4】执行git commit --amend修改命令,修改的方式如下图:
使用 git rebase -i [被修改的父级commit的唯一id] 命令进入变基操作。
【注意】:上面使用的是父级commit进入变基操作,进去操作的是父级下面的commit。
1,因为rebase状态下可以支持多种操作,这里我们要将需要修改的commit前面默认pick操作方式改为reword(也就是修改的意思)。然后按照第二步中一样的方式保存退出,进入下一个操作界面。
2,这个操作界面,可以将原本commit的描述内容进行修改,如下图第一行所示。然后继续保存退出。
3,使用git log --graph 查看修改后的结果,如下图:
根据上一步git log --graph的结果可以看出,其实上面有三个commit都是为了给让index.html以正常的表现展示出来,所以我们可以将除了readme操作之外的其他三个commit进行合并。
1,使用git rebase -i [最开始创建readme的commit唯一id]命令,进入操作界面。将这三个commit合并至其中某一个,然后保存退出进入下一步。
pick 789f15c add a index.html file #【1】表示将其他commit合并至这个commit
squash e7bf7b0 add aaaaaaa style file #【2】合并
squash 4216faf let index.html link the style file #【3】合并
# Rebase 1bb42bc..4216faf onto 1bb42bc (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
#
# Note that empty commits are commented out
~
:wq!
2,填写此次合并的描述文字,并保留原commit的描述文字,方便后续查看。
# This is the 1st commit messages:
I am trying to make a combination, Yeah! #【1】此次合并操作的描述文字
add a index.html file # 【2-1】保留的原有commit描述文字
# This is the commit message #2:
add aaaaaaa style file # 【2-2】保留的原有commit描述文字
# This is the commit message #3:
let index.html link the style file # 【2-3】保留的原有commit描述文字
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Wed Feb 27 11:42:12 2019 +0800
#
# interactive rebase in progress; onto 1bb42bc
# Last commands done (3 commands done):
# squash e7bf7b0 add aaaaaaa style file
# squash 4216faf let index.html link the style file
# No commands remaining.
# You are currently rebasing branch 'anothertest' on '1bb42bc'.
#
# Changes to be committed:
# new file: css/style.css
# new file: index.html
#
# Untracked files:
# js/
#
:wq!
3,使用git log --graph 查看合并后的版本状态。
1,基于上一步,为了演示我们将其他测试分支全部移除,只保留原本的master分支,及与index.html、style.css、readme.md相关的三个commit。
之后我们修改my-pro下的readme.md文件内容,并执行一次commit操作。然后使用git log --graph命令,查看当前的commit状态列表。
2,因为最前面跟最后面的commit都是关于readme的提交,所以我们需要将其合并。在执行git rebase -i [最下面的祖先commit]之前,记得复制改祖先commit的id(如:1bb42bc),以备使用。
进入操作窗口后,按照下面代码所示进行操作保存退出。
pick 1bb42bc8 #【1】这一句是我们自己新增的,就是将另一个操作readme的commit操作合并过来
squash 702dcbf I am the real readme.md file # 【2】这一行本来在最下面,我们移动到这一样,并修改pick至squash
pick 2b2e247 I am trying to make a combination, Yeah!
# Rebase 1bb42bc..702dcbf onto 1bb42bc (2 commands)
#
# Commands:这里本来有很多command提示,被删除了
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
:wq!
3,如果保存退出后提醒分支不连续,我们可以使用git rebase --continue继续执行下一步操作。
1,修改my-pro仓库中index.html的内容。
2,执行一次git add 操作。
3,使用 git diff -cached 查看暂存区与HEAD所含文件差异。
Yooye-2:my-pro yooye$ git diff --cached #【1】执行对比命令
diff --git a/index.html b/index.html
index 084901f..ec530c2 100644
--- a/index.html
+++ b/index.html
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
- <title>Document</title> #【2-1】未改动之前HEAD指向的旧内容
+ <title>Learn Git</title> #【2-2】改动后通过git add新增到暂存区的内容
</head>
<body>
<div class="box"></div>
1,基于上一步操作,我们再调整一下style.css文件(如:添加个背景),然后先不执行git add操作,这个时候,我们刚才编辑的style.css文件的改变就属于工作区。
2,执行git diff命令,查看工作区与之前提交的暂存区文件区别。
Yooye-2:my-pro yooye$ git diff
diff --git a/css/style.css b/css/style.css
index 20ce14c..488853c 100644
--- a/css/style.css
+++ b/css/style.css
@@ -2,4 +2,5 @@
width: 100px;
height: 100px;
border: 1px solid red;
+ background: pink;
}
\ No newline at end of file
Yooye-2:my-pro yooye$
3,如果再提交至暂存区前,修改了多个文件,然而我们只想查看某个文件的变动,例如readme.md,可以使用如下命令:
git diff -- readme.md
使用场景,我们在第六步,将index.html修改后,通过git add提交到了暂存区,如果这个时候我们反悔了,就可以使用 git reset HEAD 命令,将其恢复到与HEAD一样。测试流程如下:
*请认真填写需求信息,我们会在24小时内与您取得联系。