搜尋
首頁web前端html教學HTML基础内容详解

HTML基础内容详解

Apr 15, 2017 am 09:05 AM
html

HTML简介

什么是HTML

  • HTML(Htyper Text Markup Language):即超文本标记语言。

  • 超文本:指可以包含图片、链接,甚至音乐、程序等非文字元素。

  • 标记语言:由标记(标签)构成的语言。

什么是标签

  • 由一对尖括号包裹的单词构成,例如:

  • 标签不区分大小写, 和 一样,推荐使用小写。

  • 有些标签使用一个标签即可,叫做自闭和标签,例如:


  • 标签可以嵌套,但是不能交叉嵌套

什么是标签属性

  • 通常是以键值对形式出现的,例如 name="nick"

  • 属性只能出现在开始标签或自闭和标签中

  • 属性名字全部小写

  • 属性值必须使用双引号或单引号包裹 例如,name="nick"

  • 如果属性值和属性名完全一样.直接写属性名即可,例如:readonly

HTML5基本结构

<!DOCTYPE HTML>
<html>
    <head>
    </head>
    <body>
    </body>
</html>

HTML5如何指定字符集

  • 使用Content-Type指定字符集<br><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

  • 直接使用charset指定字符集<br><meta charset="UTF-8" />

<hr>

标签

</h3> <p>显示在浏览器的标题栏</p> <h3 id="lt-base-gt"><base/></h3> <p>为页面上的所有链接规定默认地址或默认目标。</p> <pre class="brush:php;toolbar:false"><!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Title</title>     <base href="https://segmentfault.com/u/jerry_fe/"/>     <base target="_blank" /> </head> <body>     <img src="jerry.png" alt="图片加载失败。。。"/>     <a href="https://segmentfault.com/u/jerry_fe/">my blogs</a> </body> </html></pre> <p>以上代码中,<img>的src属性时一个相对路径,因为<head>中通过base标签设置了链接的默认地址,<br>所以img的src实际的地址是“https://segmentfault.com/u/je...”。<br>而a标签中只是指定了href,并未指定target属性,所以也会使用base中设置的target属性的值。</p> <h3 id="lt-link-gt"><link/></h3> <p>引用外部文档,常见于引用外部样式。重要属性有三个:rel、href、type。<br><strong>rel用于规定文档与被链接文档之间的关系【<em>注:必须</em>】:</strong></p> <ul class=" list-paddingleft-2"> <li><p>rel="dns-prefetch"  预先解析缓存文档中使用的域名,目的是为了提高网页访问速度。使用场景:在一个网页频繁使用其他域名资源时。</p></li> <li> <p>rel="shortcut icon"或rel="icon"  在收藏和标题栏上用于显示的图标。示例:<link rel="icon" href="https://segmentfault.com/u/je...。注意:IE浏览器只支持ico格式,为了兼容IE,图片文件最好采用ico格式。</p></li><li><p>rel="stylesheet" 引用外部样式表。</p></li><li><p>rel="nofollow" 用于指示搜索引擎不要追踪(爬虫不要抓取),从而减少垃圾链接。使用场景:不希望被信任或是不希望被搜索引擎录入的网站。</p></li></ul><p><strong>href用于规定资源的路径(绝对路径/相对路径)【<em>注:必须</em>】。</strong><br/><strong>type用于规定被链接文档的MIME类型,用于明确文件的打开方式,【<em>注:非必须</em>】。例如:.css文件的MIME类型为text/css,而.ico文件的MIME类型为image/x-icon。</strong></p><h3><meta/></p> <p>用于定义与该HTML文档相关的元数据。最常见的用途是指定当前文档所用的字符集<code><meta charset="UTF-8"/></code><br>重要的属性有三个:http-equiv、name、content<br><strong>http-equiv把content属性值关联到http头部,可能的值为:</strong></p> <ul class=" list-paddingleft-2"> <li><p><strong><em>content-type</em></strong> 用于规定浏览器接受的文档类型,一般为text/html,即content的值一般设为text/html。</p></li> <li><p><strong><em>refresh</em></strong> 用于规定网页自动刷新的频率,时间以秒为单位(切记不是毫秒),也可设定刷新后跳转的路径,即content的值一般设为刷新的间隔秒数以及跳转路径。</p></li> <li> <p><strong><em>expires</em></strong> 用于设定网页到期时间,一旦到期,必须到服务器上重传。</p> <pre class="brush:php;toolbar:false"><meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta http-equiv="refresh" content="2"> <meta http-equiv="refresh" content="2;URL=https://www.baidu.com"> <meta http-equiv="expires" content="6 Jun 2016"/></pre> </li> </ul> <p><strong>name为content属性值赋予一个含义或功能,可能的值为:</strong></p> <ul class=" list-paddingleft-2"> <li><p><strong><em>keywords</em></strong> 将content值定义为供搜索引擎抓取信息的关键字</p></li> <li><p><strong><em>description</em></strong> 将content值定义为搜索引擎搜索后,在搜索结果中显示的简单网页描述</p></li> <li><p><strong><em>author</em></strong> 将content值规定为网页制作者的信息</p></li> <li> <p><strong><em>generator</em></strong> 将content值规定为网页生成工具的信息</p> <pre class="brush:php;toolbar:false"><meta name="keywords" content="我是关键字"> <meta name="description" content="我是简要描述"> <meta name="author" content="https://segmentfault.com/u/jerry_fe"> <meta name="generator" content="用以说明生成工具"></pre> </li> </ul> <p><strong>content  定义与http-equiv或name属性相关的元信息,是必要的属性。</strong></p> <hr> <h1 id="lt-body-gt-标签"><body>标签</h1> <h3 id="块级元素-block-和内联元素-inline">1.块级元素(block)和内联元素(inline)</h3> <p><strong>块级元素:</strong><h1>~<h6>、<p>、<p>、<ol>、<ul>、<table>、<form><br><strong>行内元素:</strong><code><a></code>、<img>、<input>、<span>、<textarea>、<code><sub></code>、<code><sup></code></p> <p><strong>block元素的特点:</strong></p> <ul class=" list-paddingleft-2"> <li><p>总是在新行上开始;</p></li> <li><p>行高以及外边距和内边距都可控制;</p></li> <li><p>宽度默认是容器的100%,除非设定一个宽度;</p></li> <li><p>可容纳内联元素和其他块元素。</p></li> </ul> <p><strong>inline(内联)元素的特点:</strong></p> <ul class=" list-paddingleft-2"> <li><p>和其他元素都在一行上;</p></li> <li><p>行高及外边距和内边距不可改变;</p></li> <li><p>宽度就是它的文字或图片的宽度,不可改变;</p></li> <li><p>只能容纳文本或者其他内联元素。</p></li> </ul> <p><strong>行内元素,需要注意:</strong></p> <ul class=" list-paddingleft-2"> <li><p>设置宽度width无效;</p></li> <li><p>设置高度height无效,可以通过line-height来设置;</p></li> <li><p>设置margin只有左右margin有效,上下无效;</p></li> <li><p>设置padding只有左右padding有效,上下则无效。注意元素范围是增大了,但是对元素周围的内容是没影响的。</p></li> </ul> <h3 id="基本标签">2.基本标签</h3> <p><h1>~<h6>: 标题标签<br><p>: 段落标签,包裹的内容被换行,并且上下内容之间有一行空白。<br>    style="text-indent: 2em"可以设置样式为首行缩进两个字符。<br>    <blockquote></blockquote>可以用来设置整个段落的缩进。<br><code><strong> <b></code>: 加粗标签<br><strike>: 为文字加上一条中线<br><u>: 文字下方加下划线<br><code><em> <i></code>: 文字变成斜体<br><code><sup> <sub></code>: 上角标 和 下角标<br><code><br></code>: 换行<br><code><hr></code>: 水平线<br><p>: 块标签。</p> <pre class="brush:php;toolbar:false">  块级标签常用于布局,行级标签常用于显示内容。   p的显示通常使用id或class来标识。id为唯一的标签标识,class为标签的类标识。   p的大小是由内容来决定的,默认情况下,高度由内容的高度决定,宽度适应屏幕。</pre> <p><span>: 可以容纳其他元素,是一个容器。</p> <h3 id="特殊符号">3.特殊符号</h3> <pre class="brush:php;toolbar:false">"    &quot; < &lt; >    &gt; 空格  ©    &copy; &    &amp; ¥    &yen; £    &pound;</pre> <h3 id="code-lt-a-gt-code-超链接标签-锚标签">4.<code><a></code>超链接标签(锚标签)</h3> <p>重要属性有三个:href、target、name</p> <ul class=" list-paddingleft-2"> <li><p>href  超链接地址:可以是Web上任意资源,包括图片,网页,样式,脚本文件等。href="#"时,表示被链接页面就是当前页面。</p></li> <li><p>target  文档打开时要显示的目标位置,属性值一般有:_blank(新窗口中打开)、_self(默认,在超链接所在的容器中打开)、_parent(在超链接的父容器中打开)、_top(超链接所在的顶层容器中打开)、name(名称为name的框架中打开)。</p></li> <li><p>name  锚标记名称。作用:跳转到文档的某个地方。返回首页。</p></li> </ul> <p>网页跳转:</p> <pre class="brush:php;toolbar:false"><a href="https://segmentfault.com/u/jerry_fe/" target="_blank">Nick Blogs</a></pre> <p>锚标记跳转:</p> <pre class="brush:php;toolbar:false"><a name="mao"><h3>这是一个锚标记</h3></a> <p style="height: 800px"></p> <a href="#mao">跳转至锚标记</a></pre> <h3 id="lt-img-gt-图片标签">5.<img>图片标签</h3> <p>重要属性有:src、title、alt、width、height、align。</p> <ul class=" list-paddingleft-2"> <li><p>src  图片地址</p></li> <li><p>title  鼠标悬浮在图片上的文字</p></li> <li><p>alt  图片找不到时要替换的文字。如果图片资源使用的是外网资源,则不会显示要替换的文字。如果使用的是本网站的资源(相对路径给出),则找不到图片时会显示替换的文字,并保留图片设置的宽高结构。</p></li> <li><p>align  图片周围文字的垂直对齐情况。常用的属性值有:top(与图片的顶部对齐)、middle(与图片的中部对齐)、bottom(默认,与图片的底部对齐)。</p></li> <li><p>width  图片的宽</p></li> <li> <p>height  图片的高 (宽高两个属性,若只写一个会,自动等比缩放)</p> <pre class="brush:php;toolbar:false"><img src="https://segmentfault.com/u/jerry_fe/jerry.png" alt="图片加载失败。。。" title="This is a picture."/></pre> </li> </ul> <h3 id="列表标签">6.列表标签</h3> <p><ul>: 无序列表标签</p> <pre class="brush:php;toolbar:false">    <li>: 列表中的每一项.</pre> <p><ol>: 有序列表标签</p> <pre class="brush:php;toolbar:false">    <li>: 列表中的每一项.</pre> <p><li>主要的属性有:type、value两个:</p> <ul class=" list-paddingleft-2"> <li><p>type指明列表项的类型,属性值有:A,a,I,i,1,disc(实心圆),square(实心正方形),circle(空心圆)。</p></li> <li><p>value表示序号值从几开始。</p></li> </ul> <p><dl> 定义列表</p> <ul class=" list-paddingleft-2"> <li><p><dt> 列表标题</p></li> <li> <p><dd> 列表项</p> <p><ul></p> <pre class="brush:php;toolbar:false"> <li type="circle">A</li>  <li type="1">B</li>  <li type="1">C</li></pre> <p></ul><br> <ol></p> <pre class="brush:php;toolbar:false"> <li value="3">3</li>  <li>4</li></pre> <p></ol><br> <dl></p> <pre class="brush:php;toolbar:false"> <dt><i>标题</i></dt>  <dd>第一项</dd>  <dd>第二项</dd>  <dd>第三项</dd></pre> <p></dl></p> </li> </ul> <h3 id="lt-table-gt-表格标签">7.<table> 表格标签</h3> <table> <thead><tr class="firstRow"> <th>序号</th> <th>姓名</th> </tr></thead> <tbody> <tr> <th>1.</th> <td>Jerry</td> </tr> <tr> <th>2.</th> <td>Ferry</td> </tr> </tbody> </table> <pre class="brush:php;toolbar:false"><table border="1">     <thead>         <tr>             <th>序号</th>             <th>姓名</th>         </tr>     </thead>     <tbody>         <tr>             <th>1.</th>             <td>Jerry</td>         </tr>         <tr>             <th>2.</th>             <td>Ferry</td>         </tr>     </tbody> </table></pre> <p><strong>table标签的主要属性:</strong></p> <ul class=" list-paddingleft-2"> <li><p><strong>border</strong>     表格边框</p></li> <li><p><strong>align</strong>      水平对齐方式</p></li> <li><p><strong>bgcolor</strong>    背景颜色</p></li> <li><p><strong>cellpadding</strong> 内边距,单元格与内容之间的距离</p></li> <li><p><strong>cellspacing</strong> 外边距,单元格的间距,设置为0时,表格变为实线表格</p></li> <li><p><strong>width</strong> 表格的宽度,可以用%或者像素,最好通过css来设置长宽</p></li> </ul> <p><strong><caption></strong> 表格的标题<br><strong><tr></strong> 表格的行<br><strong><th></strong> 表格的表头名称,与<td>不同在于文字采用加粗居中的形式显示<br><strong><td></strong> 单元格,用来显示表格内容<br><strong><thead></strong> 表格头部,使结构更加分明<br><strong><tbody></strong> 表格主体部分,使结构更加分明<br><strong>rowspan</strong> 单元格竖跨多少行,作用在th或者td上<br><strong>colspan</strong> 单元格横跨多少列(即合并单元格),作用在th或者td上。(即横跨、竖跨都是作用在th或td上)</p> <h3 id="lt-form-gt-表单标签">8.<form>表单标签</h3> <p><strong>表单属性</strong><br>HTML 表单用于接收不同类型的用户输入,用户提交表单时向服务器传输数据,从而实现用户与Web服务器的交互。<br>属性:action、method、enctype</p> <ul class=" list-paddingleft-2"> <li><p><strong><em>action</em></strong> 表单要提交的地址,用于处理表单的内容(一般是提交到后台的一个接口,这个接口可以是java写成的,提交到这个接口后后台就知道如何处理这些数据了)。</p></li> <li><p><strong><em>method</em></strong>  提交的方法,默认是get方式提交。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>get</strong>:1.提交的键值对显示在地址栏url后面; 2.安全性相对较差; 3.对提交内容的长度有限制</p></li> <li><p><strong>post</strong>:1.提交的键值对不显示在地址栏; 2.安全性相对较高; 3.对提交内容的长度理论上无限制</p></li> </ul> <li><p><strong><em>enctype</em></strong> 对表单数据进行编码</p></li> </ul> <p><strong>表单元素</strong><br><input> type属性可能的值:</p> <ul class=" list-paddingleft-2"> <li><p><strong><em>text</em></strong> 文本框输入(type的默认类型)</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>autocomplete</strong>(自动完成输入的内容,要求表单元素要有name属性才有自动完成的效果,off表示自动完成不可用,on表示自动完成可用)</p></li> <li><p><strong>disabled</strong>(设置或者获取控件的状态,默认是false即可用,等于true时不可用,不能输入内容)</p></li> </ul> <li><p><strong><em>password</em></strong>密码框。(以下属性text和password共有)</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>size</strong>(指定表单元素的初始宽度。当type为text或password时,表单元素的大小以字符为单位,对于其他元素,宽度以像素为单位)</p></li> <li><p><strong>maxlength</strong>(type为text或password时,表示输入的最大字符数),有利于防止sql的注入攻击</p></li> <li><p><strong>readonly</strong>设置为只读状态</p></li> <li><p><strong>placeholder</strong>设置框内预置内容(灰色),焦点选中时消失</p></li> </ul> <li><p><strong><em>radio</em></strong> 单选按钮</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>name</strong>(将name的值设置为相同值,才表示一组数据,才能实现单选功能)</p></li> <li><p><strong>value</strong>(必须要写,提交到服务器的key值,实际开发过程中value一般是编号)</p></li> <li><p><strong>checked</strong>(设置是否被默认选中)</p></li> </ul> <li><p><strong><em>checkbox</em></strong>  复选框</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>name</strong>(将name的值设置为相同值,才表示一组数据,才能添加到同一value值列表并提交到服务器)</p></li> <li><p><strong>value</strong>(必须要写,提交到服务器的key值,实际开发过程中value一般是编号)</p></li> <li><p><strong>checked</strong>(设置是否被默认选中)</p></li> </ul> <li><p><strong><em>file</em></strong>  文件域,用于上传文件(不同的浏览器表现形式不同)</p></li> <li><p><strong><em>submit</em></strong>  提交按钮。用于提交表单。</p></li> <li><p><strong><em>reset</em></strong>  重置按钮。清空表单的输入,恢复到表单默认的状态。</p></li> <li><p><strong><em>button</em></strong>  普通按钮。一般结合javascript使用。</p></li> <li><p><strong><em>image</em></strong>  图片按钮,用来提交表单,与submit是一样的效果。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>src(图片路径)</p></li></ul> <li><p><strong><em>hidden</em></strong>  隐藏字段。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value(隐藏的内容)</p></li></ul> <li><p><strong><em>color</em></strong>  颜色标签。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value 指定颜色值(采用#十六进制数表示)。</p></li></ul> <li><p><strong><em>date</em></strong>  日期。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value值指定默认的日期,格式为<strong><em>*-</em></strong>-*(年月日)。</p></li></ul> <li><p><strong><em>datetime-local</em></strong>  显示本地时间</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value值指定默认的时间,格式为2017-04-13T23:10:10(年月日T时分秒)。</p></li></ul> <li><p><strong><em>number</em></strong>  数字向上或者向下滑动。可以填数字然后向上或者向下选择不同的值。</p></li> <li><p><strong><em>range</em></strong>  滑动标签。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p>min(指定最小值)</p></li> <li><p>max(指定最大值)</p></li> <li><p>value(指定当前默认值)。</p></li> </ul> <li><p><strong><em>week</em></strong>  每年的周数。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value指定哪一年第几周,格式为2017-W20(2017年第20周)。</p></li></ul> </ul> <p><textarea> 文本域标签。默认表现形式是可以输入很多行文本的文本框。</p> <ul class=" list-paddingleft-2"> <li><p><strong>name</strong> 表单提交项的key</p></li> <li><p><strong>cols</strong> 设置文本域宽度</p></li> <li><p><strong>rows</strong> 设置文本域高度,即行数</p></li> </ul> <p><select> 下拉框标签。使用时要结合<option>子标签一起使用。</p> <ul class=" list-paddingleft-2"> <li><p><strong>name</strong> 表单提交项的key</p></li> <li><p><strong>size</strong> 选项个数</p></li> <li><p><strong>multiple</strong> 多选</p></li> <li><p><strong><option></strong> 下拉选中的每一项</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p>value(表单提交项的值)</p></li> <li><p>selected(selected下拉项默认被选中)</p></li> </ul> <li><p><strong><optgroup></strong> 为同类项加上分组</p></li> </ul> <p><label> 把元素与文本结合起来<br>友好设计:不只是选中复选框才能选中并打钩,要求点击对应的文字也能选中该复选框。<br>这种情况下要用到<label>标签的for属性(设置或获取给定标签对象指定到的对象,值=另一个元素的id号即可)</p> <pre class="brush:php;toolbar:false"><label for="name">姓名</label> <input id="name" type="text"></pre> <p><fieldset> 对表单中的相关元素进行分组</p> <pre class="brush:php;toolbar:false"><fieldset>     <legend>温馨提示</legend>     <p align="middle">不要忘记点赞哦 ==</p> </fieldset></pre> <p>value: 表单提交项的值<br>对于不同的输入类型,value 属性的用法也不同:</p> <ul class=" list-paddingleft-2"> <li><p>type="button", "reset", "submit" - 定义按钮上的显示的文本</p></li> <li><p>type="text", "password", "hidden" - 定义输入字段的初始值</p></li> <li><p>type="checkbox", "radio", "image" - 定义与输入相关联的值</p></li> </ul> <p class="article fmt article__content"><br></p> <h1 id="HTML简介">HTML简介</h1> <h3 id="什么是HTML">什么是HTML</h3> <ul class=" list-paddingleft-2"> <li><p>HTML(Htyper Text Markup Language):即超文本标记语言。</p></li> <li><p>超文本:指可以包含图片、链接,甚至音乐、程序等非文字元素。</p></li> <li><p>标记语言:由标记(标签)构成的语言。</p></li> </ul> <h3 id="什么是标签">什么是标签</h3> <ul class=" list-paddingleft-2"> <li><p>由一对尖括号包裹的单词构成,例如:<html></p></li> <li><p>标签不区分大小写,<html> 和 <HTML>一样,推荐使用小写。</p></li> <li><p>有些标签使用一个标签即可,叫做自闭和标签,例如: <br/><hr/><input/><img/></p></li> <li><p>标签可以嵌套,但是不能交叉嵌套</p></li> </ul> <h3 id="什么是标签属性">什么是标签属性</h3> <ul class=" list-paddingleft-2"> <li><p>通常是以键值对形式出现的,例如 name="nick"</p></li> <li><p>属性只能出现在开始标签或自闭和标签中</p></li> <li><p>属性名字全部小写</p></li> <li><p>属性值必须使用双引号或单引号包裹 例如,name="nick"</p></li> <li><p>如果属性值和属性名完全一样.直接写属性名即可,例如:readonly</p></li> </ul> <h3 id="HTML-基本结构">HTML5基本结构</h3> <pre class="brush:php;toolbar:false"><!DOCTYPE HTML> <html>     <head>     </head>     <body>     </body> </html></pre> <h3 id="HTML-如何指定字符集">HTML5如何指定字符集</h3> <ul class=" list-paddingleft-2"> <li><p>使用Content-Type指定字符集<br><code><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /></code></p></li> <li><p>直接使用charset指定字符集<br><code><meta charset="UTF-8" /></code></p></li> </ul> <hr> <h1 id="lt-head-gt-标签"><head>标签</h1> <h3 id="lt-title-gt"><title></h3> <p>显示在浏览器的标题栏</p> <h3 id="lt-base-gt"><base/></h3> <p>为页面上的所有链接规定默认地址或默认目标。</p> <pre class="brush:php;toolbar:false"><!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Title</title>     <base href="https://segmentfault.com/u/jerry_fe/"/>     <base target="_blank" /> </head> <body>     <img src="jerry.png" alt="图片加载失败。。。"/>     <a href="https://segmentfault.com/u/jerry_fe/">my blogs</a> </body> </html></pre> <p>以上代码中,<img>的src属性时一个相对路径,因为<head>中通过base标签设置了链接的默认地址,<br>所以img的src实际的地址是“https://segmentfault.com/u/je...”。<br>而a标签中只是指定了href,并未指定target属性,所以也会使用base中设置的target属性的值。</p> <h3 id="lt-link-gt"><link/></h3> <p>引用外部文档,常见于引用外部样式。重要属性有三个:rel、href、type。<br><strong>rel用于规定文档与被链接文档之间的关系【<em>注:必须</em>】:</strong></p> <ul class=" list-paddingleft-2"> <li><p>rel="dns-prefetch"  预先解析缓存文档中使用的域名,目的是为了提高网页访问速度。使用场景:在一个网页频繁使用其他域名资源时。</p></li> <li> <p>rel="shortcut icon"或rel="icon"  在收藏和标题栏上用于显示的图标。示例:<link rel="icon" href="https://segmentfault.com/u/je...。注意:IE浏览器只支持ico格式,为了兼容IE,图片文件最好采用ico格式。</p></li><li><p>rel="stylesheet" 引用外部样式表。</p></li><li><p>rel="nofollow" 用于指示搜索引擎不要追踪(爬虫不要抓取),从而减少垃圾链接。使用场景:不希望被信任或是不希望被搜索引擎录入的网站。</p></li></ul><p><strong>href用于规定资源的路径(绝对路径/相对路径)【<em>注:必须</em>】。</strong><br/><strong>type用于规定被链接文档的MIME类型,用于明确文件的打开方式,【<em>注:非必须</em>】。例如:.css文件的MIME类型为text/css,而.ico文件的MIME类型为image/x-icon。</strong></p><h3><meta/></p> <p>用于定义与该HTML文档相关的元数据。最常见的用途是指定当前文档所用的字符集<code><meta charset="UTF-8"/></code><br>重要的属性有三个:http-equiv、name、content<br><strong>http-equiv把content属性值关联到http头部,可能的值为:</strong></p> <ul class=" list-paddingleft-2"> <li><p><strong><em>content-type</em></strong> 用于规定浏览器接受的文档类型,一般为text/html,即content的值一般设为text/html。</p></li> <li><p><strong><em>refresh</em></strong> 用于规定网页自动刷新的频率,时间以秒为单位(切记不是毫秒),也可设定刷新后跳转的路径,即content的值一般设为刷新的间隔秒数以及跳转路径。</p></li> <li> <p><strong><em>expires</em></strong> 用于设定网页到期时间,一旦到期,必须到服务器上重传。</p> <pre class="brush:php;toolbar:false"><meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta http-equiv="refresh" content="2"> <meta http-equiv="refresh" content="2;URL=https://www.baidu.com"> <meta http-equiv="expires" content="6 Jun 2016"/></pre> </li> </ul> <p><strong>name为content属性值赋予一个含义或功能,可能的值为:</strong></p> <ul class=" list-paddingleft-2"> <li><p><strong><em>keywords</em></strong> 将content值定义为供搜索引擎抓取信息的关键字</p></li> <li><p><strong><em>description</em></strong> 将content值定义为搜索引擎搜索后,在搜索结果中显示的简单网页描述</p></li> <li><p><strong><em>author</em></strong> 将content值规定为网页制作者的信息</p></li> <li> <p><strong><em>generator</em></strong> 将content值规定为网页生成工具的信息</p> <pre class="brush:php;toolbar:false"><meta name="keywords" content="我是关键字"> <meta name="description" content="我是简要描述"> <meta name="author" content="https://segmentfault.com/u/jerry_fe"> <meta name="generator" content="用以说明生成工具"></pre> </li> </ul> <p><strong>content  定义与http-equiv或name属性相关的元信息,是必要的属性。</strong></p> <hr> <h1 id="lt-body-gt-标签"><body>标签</h1> <h3 id="块级元素-block-和内联元素-inline">1.块级元素(block)和内联元素(inline)</h3> <p><strong>块级元素:</strong><h1>~<h6>、<p>、<p>、<ol>、<ul>、<table>、<form><br><strong>行内元素:</strong><code><a></code>、<img>、<input>、<span>、<textarea>、<code><sub></code>、<code><sup></code></p> <p><strong>block元素的特点:</strong></p> <ul class=" list-paddingleft-2"> <li><p>总是在新行上开始;</p></li> <li><p>行高以及外边距和内边距都可控制;</p></li> <li><p>宽度默认是容器的100%,除非设定一个宽度;</p></li> <li><p>可容纳内联元素和其他块元素。</p></li> </ul> <p><strong>inline(内联)元素的特点:</strong></p> <ul class=" list-paddingleft-2"> <li><p>和其他元素都在一行上;</p></li> <li><p>行高及外边距和内边距不可改变;</p></li> <li><p>宽度就是它的文字或图片的宽度,不可改变;</p></li> <li><p>只能容纳文本或者其他内联元素。</p></li> </ul> <p><strong>行内元素,需要注意:</strong></p> <ul class=" list-paddingleft-2"> <li><p>设置宽度width无效;</p></li> <li><p>设置高度height无效,可以通过line-height来设置;</p></li> <li><p>设置margin只有左右margin有效,上下无效;</p></li> <li><p>设置padding只有左右padding有效,上下则无效。注意元素范围是增大了,但是对元素周围的内容是没影响的。</p></li> </ul> <h3 id="基本标签">2.基本标签</h3> <p><h1>~<h6>: 标题标签<br><p>: 段落标签,包裹的内容被换行,并且上下内容之间有一行空白。<br>    style="text-indent: 2em"可以设置样式为首行缩进两个字符。<br>    <blockquote></blockquote>可以用来设置整个段落的缩进。<br><code><strong> <b></code>: 加粗标签<br><strike>: 为文字加上一条中线<br><u>: 文字下方加下划线<br><code><em> <i></code>: 文字变成斜体<br><code><sup> <sub></code>: 上角标 和 下角标<br><code><br></code>: 换行<br><code><hr></code>: 水平线<br><p>: 块标签。</p> <pre class="brush:php;toolbar:false">  块级标签常用于布局,行级标签常用于显示内容。   p的显示通常使用id或class来标识。id为唯一的标签标识,class为标签的类标识。   p的大小是由内容来决定的,默认情况下,高度由内容的高度决定,宽度适应屏幕。</pre> <p><span>: 可以容纳其他元素,是一个容器。</p> <h3 id="特殊符号">3.特殊符号</h3> <pre class="brush:php;toolbar:false">"    &quot; < &lt; >    &gt; 空格  ©    &copy; &    &amp; ¥    &yen; £    &pound;</pre> <h3 id="code-lt-a-gt-code-超链接标签-锚标签">4.<code><a></code>超链接标签(锚标签)</h3> <p>重要属性有三个:href、target、name</p> <ul class=" list-paddingleft-2"> <li><p>href  超链接地址:可以是Web上任意资源,包括图片,网页,样式,脚本文件等。href="#"时,表示被链接页面就是当前页面。</p></li> <li><p>target  文档打开时要显示的目标位置,属性值一般有:_blank(新窗口中打开)、_self(默认,在超链接所在的容器中打开)、_parent(在超链接的父容器中打开)、_top(超链接所在的顶层容器中打开)、name(名称为name的框架中打开)。</p></li> <li><p>name  锚标记名称。作用:跳转到文档的某个地方。返回首页。</p></li> </ul> <p>网页跳转:</p> <pre class="brush:php;toolbar:false"><a href="https://segmentfault.com/u/jerry_fe/" target="_blank">Nick Blogs</a></pre> <p>锚标记跳转:</p> <pre class="brush:php;toolbar:false"><a name="mao"><h3>这是一个锚标记</h3></a> <p style="height: 800px"></p> <a href="#mao">跳转至锚标记</a></pre> <h3 id="lt-img-gt-图片标签">5.<img>图片标签</h3> <p>重要属性有:src、title、alt、width、height、align。</p> <ul class=" list-paddingleft-2"> <li><p>src  图片地址</p></li> <li><p>title  鼠标悬浮在图片上的文字</p></li> <li><p>alt  图片找不到时要替换的文字。如果图片资源使用的是外网资源,则不会显示要替换的文字。如果使用的是本网站的资源(相对路径给出),则找不到图片时会显示替换的文字,并保留图片设置的宽高结构。</p></li> <li><p>align  图片周围文字的垂直对齐情况。常用的属性值有:top(与图片的顶部对齐)、middle(与图片的中部对齐)、bottom(默认,与图片的底部对齐)。</p></li> <li><p>width  图片的宽</p></li> <li> <p>height  图片的高 (宽高两个属性,若只写一个会,自动等比缩放)</p> <pre class="brush:php;toolbar:false"><img src="https://segmentfault.com/u/jerry_fe/jerry.png" alt="图片加载失败。。。" title="This is a picture."/></pre> </li> </ul> <h3 id="列表标签">6.列表标签</h3> <p><ul>: 无序列表标签</p> <pre class="brush:php;toolbar:false">    <li>: 列表中的每一项.</pre> <p><ol>: 有序列表标签</p> <pre class="brush:php;toolbar:false">    <li>: 列表中的每一项.</pre> <p><li>主要的属性有:type、value两个:</p> <ul class=" list-paddingleft-2"> <li><p>type指明列表项的类型,属性值有:A,a,I,i,1,disc(实心圆),square(实心正方形),circle(空心圆)。</p></li> <li><p>value表示序号值从几开始。</p></li> </ul> <p><dl> 定义列表</p> <ul class=" list-paddingleft-2"> <li><p><dt> 列表标题</p></li> <li> <p><dd> 列表项</p> <p><ul></p> <pre class="brush:php;toolbar:false"> <li type="circle">A</li>  <li type="1">B</li>  <li type="1">C</li></pre> <p></ul><br> <ol></p> <pre class="brush:php;toolbar:false"> <li value="3">3</li>  <li>4</li></pre> <p></ol><br> <dl></p> <pre class="brush:php;toolbar:false"> <dt><i>标题</i></dt>  <dd>第一项</dd>  <dd>第二项</dd>  <dd>第三项</dd></pre> <p></dl></p> </li> </ul> <h3 id="lt-table-gt-表格标签">7.<table> 表格标签</h3> <table> <thead><tr class="firstRow"> <th>序号</th> <th>姓名</th> </tr></thead> <tbody> <tr> <th>1.</th> <td>Jerry</td> </tr> <tr> <th>2.</th> <td>Ferry</td> </tr> </tbody> </table> <pre class="brush:php;toolbar:false"><table border="1">     <thead>         <tr>             <th>序号</th>             <th>姓名</th>         </tr>     </thead>     <tbody>         <tr>             <th>1.</th>             <td>Jerry</td>         </tr>         <tr>             <th>2.</th>             <td>Ferry</td>         </tr>     </tbody> </table></pre> <p><strong>table标签的主要属性:</strong></p> <ul class=" list-paddingleft-2"> <li><p><strong>border</strong>     表格边框</p></li> <li><p><strong>align</strong>      水平对齐方式</p></li> <li><p><strong>bgcolor</strong>    背景颜色</p></li> <li><p><strong>cellpadding</strong> 内边距,单元格与内容之间的距离</p></li> <li><p><strong>cellspacing</strong> 外边距,单元格的间距,设置为0时,表格变为实线表格</p></li> <li><p><strong>width</strong> 表格的宽度,可以用%或者像素,最好通过css来设置长宽</p></li> </ul> <p><strong><caption></strong> 表格的标题<br><strong><tr></strong> 表格的行<br><strong><th></strong> 表格的表头名称,与<td>不同在于文字采用加粗居中的形式显示<br><strong><td></strong> 单元格,用来显示表格内容<br><strong><thead></strong> 表格头部,使结构更加分明<br><strong><tbody></strong> 表格主体部分,使结构更加分明<br><strong>rowspan</strong> 单元格竖跨多少行,作用在th或者td上<br><strong>colspan</strong> 单元格横跨多少列(即合并单元格),作用在th或者td上。(即横跨、竖跨都是作用在th或td上)</p> <h3 id="lt-form-gt-表单标签">8.<form>表单标签</h3> <p><strong>表单属性</strong><br>HTML 表单用于接收不同类型的用户输入,用户提交表单时向服务器传输数据,从而实现用户与Web服务器的交互。<br>属性:action、method、enctype</p> <ul class=" list-paddingleft-2"> <li><p><strong><em>action</em></strong> 表单要提交的地址,用于处理表单的内容(一般是提交到后台的一个接口,这个接口可以是java写成的,提交到这个接口后后台就知道如何处理这些数据了)。</p></li> <li><p><strong><em>method</em></strong>  提交的方法,默认是get方式提交。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>get</strong>:1.提交的键值对显示在地址栏url后面; 2.安全性相对较差; 3.对提交内容的长度有限制</p></li> <li><p><strong>post</strong>:1.提交的键值对不显示在地址栏; 2.安全性相对较高; 3.对提交内容的长度理论上无限制</p></li> </ul> <li><p><strong><em>enctype</em></strong> 对表单数据进行编码</p></li> </ul> <p><strong>表单元素</strong><br><input> type属性可能的值:</p> <ul class=" list-paddingleft-2"> <li><p><strong><em>text</em></strong> 文本框输入(type的默认类型)</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>autocomplete</strong>(自动完成输入的内容,要求表单元素要有name属性才有自动完成的效果,off表示自动完成不可用,on表示自动完成可用)</p></li> <li><p><strong>disabled</strong>(设置或者获取控件的状态,默认是false即可用,等于true时不可用,不能输入内容)</p></li> </ul> <li><p><strong><em>password</em></strong>密码框。(以下属性text和password共有)</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>size</strong>(指定表单元素的初始宽度。当type为text或password时,表单元素的大小以字符为单位,对于其他元素,宽度以像素为单位)</p></li> <li><p><strong>maxlength</strong>(type为text或password时,表示输入的最大字符数),有利于防止sql的注入攻击</p></li> <li><p><strong>readonly</strong>设置为只读状态</p></li> <li><p><strong>placeholder</strong>设置框内预置内容(灰色),焦点选中时消失</p></li> </ul> <li><p><strong><em>radio</em></strong> 单选按钮</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>name</strong>(将name的值设置为相同值,才表示一组数据,才能实现单选功能)</p></li> <li><p><strong>value</strong>(必须要写,提交到服务器的key值,实际开发过程中value一般是编号)</p></li> <li><p><strong>checked</strong>(设置是否被默认选中)</p></li> </ul> <li><p><strong><em>checkbox</em></strong>  复选框</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p><strong>name</strong>(将name的值设置为相同值,才表示一组数据,才能添加到同一value值列表并提交到服务器)</p></li> <li><p><strong>value</strong>(必须要写,提交到服务器的key值,实际开发过程中value一般是编号)</p></li> <li><p><strong>checked</strong>(设置是否被默认选中)</p></li> </ul> <li><p><strong><em>file</em></strong>  文件域,用于上传文件(不同的浏览器表现形式不同)</p></li> <li><p><strong><em>submit</em></strong>  提交按钮。用于提交表单。</p></li> <li><p><strong><em>reset</em></strong>  重置按钮。清空表单的输入,恢复到表单默认的状态。</p></li> <li><p><strong><em>button</em></strong>  普通按钮。一般结合javascript使用。</p></li> <li><p><strong><em>image</em></strong>  图片按钮,用来提交表单,与submit是一样的效果。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>src(图片路径)</p></li></ul> <li><p><strong><em>hidden</em></strong>  隐藏字段。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value(隐藏的内容)</p></li></ul> <li><p><strong><em>color</em></strong>  颜色标签。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value 指定颜色值(采用#十六进制数表示)。</p></li></ul> <li><p><strong><em>date</em></strong>  日期。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value值指定默认的日期,格式为<strong><em>*-</em></strong>-*(年月日)。</p></li></ul> <li><p><strong><em>datetime-local</em></strong>  显示本地时间</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value值指定默认的时间,格式为2017-04-13T23:10:10(年月日T时分秒)。</p></li></ul> <li><p><strong><em>number</em></strong>  数字向上或者向下滑动。可以填数字然后向上或者向下选择不同的值。</p></li> <li><p><strong><em>range</em></strong>  滑动标签。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p>min(指定最小值)</p></li> <li><p>max(指定最大值)</p></li> <li><p>value(指定当前默认值)。</p></li> </ul> <li><p><strong><em>week</em></strong>  每年的周数。</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"><li><p>value指定哪一年第几周,格式为2017-W20(2017年第20周)。</p></li></ul> </ul> <p><textarea> 文本域标签。默认表现形式是可以输入很多行文本的文本框。</p> <ul class=" list-paddingleft-2"> <li><p><strong>name</strong> 表单提交项的key</p></li> <li><p><strong>cols</strong> 设置文本域宽度</p></li> <li><p><strong>rows</strong> 设置文本域高度,即行数</p></li> </ul> <p><select> 下拉框标签。使用时要结合<option>子标签一起使用。</p> <ul class=" list-paddingleft-2"> <li><p><strong>name</strong> 表单提交项的key</p></li> <li><p><strong>size</strong> 选项个数</p></li> <li><p><strong>multiple</strong> 多选</p></li> <li><p><strong><option></strong> 下拉选中的每一项</p></li> <ul class=" list-paddingleft-2" style="list-style-type: square;"> <li><p>value(表单提交项的值)</p></li> <li><p>selected(selected下拉项默认被选中)</p></li> </ul> <li><p><strong><optgroup></strong> 为同类项加上分组</p></li> </ul> <p><label> 把元素与文本结合起来<br>友好设计:不只是选中复选框才能选中并打钩,要求点击对应的文字也能选中该复选框。<br>这种情况下要用到<label>标签的for属性(设置或获取给定标签对象指定到的对象,值=另一个元素的id号即可)</p> <pre class="brush:php;toolbar:false"><label for="name">姓名</label> <input id="name" type="text"></pre> <p><fieldset> 对表单中的相关元素进行分组</p> <pre class="brush:php;toolbar:false"><fieldset>     <legend>温馨提示</legend>     <p align="middle">不要忘记点赞哦 ==</p> </fieldset></pre> <p>value: 表单提交项的值<br>对于不同的输入类型,value 属性的用法也不同:</p> <ul class=" list-paddingleft-2"> <li><p>type="button", "reset", "submit" - 定义按钮上的显示的文本</p></li> <li><p>type="text", "password", "hidden" - 定义输入字段的初始值</p></li> <li><p>type="checkbox", "radio", "image" - 定义与输入相关联的值</p></li> </ul> <p class="comments-box-content"><br></p> </li> </ul> </li> </ul><p>以上是HTML基础内容详解的詳細內容。更多資訊請關注PHP中文網其他相關文章!</p></div><div class="wzconShengming_sp"><div class="bzsmdiv_sp">陳述</div><div>本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn</div></div></div><div class="phpgenera_Details_mainL4"><div class="phpmain1_2_top"><a href="javascript:void(0);" class="phpmain1_2_top_title">相關文章<img class="lazy" data-src="/static/imghwm/index2_title2.png" src="/static/imghw/default1.png" alt="" /></a></div><div class="phpgenera_Details_mainL4_info"><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796796249.html" title="HTML:是編程語言還是其他?" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174464723172609.jpg?x-oss-process=image/resize,p_40" alt="HTML:是編程語言還是其他?" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796796249.html" title="HTML:是編程語言還是其他?" class="phphistorical_Version2_mids_title">HTML:是編程語言還是其他?</a><span class="Articlelist_txts_time">Apr 15, 2025 am 12:13 AM</span><p class="Articlelist_txts_p">HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增強WebevebDevelopment。</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796795665.html" title="HTML:建立網頁的結構" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174456085285529.jpg?x-oss-process=image/resize,p_40" alt="HTML:建立網頁的結構" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796795665.html" title="HTML:建立網頁的結構" class="phphistorical_Version2_mids_title">HTML:建立網頁的結構</a><span class="Articlelist_txts_time">Apr 14, 2025 am 12:14 AM</span><p class="Articlelist_txts_p">HTML是構建網頁結構的基石。 1.HTML定義內容結構和語義,使用、、等標籤。 2.提供語義化標記,如、、等,提升SEO效果。 3.通過標籤實現用戶交互,需注意表單驗證。 4.使用、等高級元素結合JavaScript實現動態效果。 5.常見錯誤包括標籤未閉合和屬性值未加引號,需使用驗證工具。 6.優化策略包括減少HTTP請求、壓縮HTML、使用語義化標籤等。</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796795191.html" title="從文本到網站:HTML的力量" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174447404295304.jpg?x-oss-process=image/resize,p_40" alt="從文本到網站:HTML的力量" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796795191.html" title="從文本到網站:HTML的力量" class="phphistorical_Version2_mids_title">從文本到網站:HTML的力量</a><span class="Articlelist_txts_time">Apr 13, 2025 am 12:07 AM</span><p class="Articlelist_txts_p">HTML是一種用於構建網頁的語言,通過標籤和屬性定義網頁結構和內容。 1)HTML通過標籤組織文檔結構,如、。 2)瀏覽器解析HTML構建DOM並渲染網頁。 3)HTML5的新特性如、、增強了多媒體功能。 4)常見錯誤包括標籤未閉合和屬性值未加引號。 5)優化建議包括使用語義化標籤和減少文件大小。</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796794693.html" title="了解HTML,CSS和JavaScript:初學者指南" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174438733162787.jpg?x-oss-process=image/resize,p_40" alt="了解HTML,CSS和JavaScript:初學者指南" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796794693.html" title="了解HTML,CSS和JavaScript:初學者指南" class="phphistorical_Version2_mids_title">了解HTML,CSS和JavaScript:初學者指南</a><span class="Articlelist_txts_time">Apr 12, 2025 am 12:02 AM</span><p class="Articlelist_txts_p">WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796794180.html" title="HTML的角色:構建Web內容" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174430155217186.jpg?x-oss-process=image/resize,p_40" alt="HTML的角色:構建Web內容" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796794180.html" title="HTML的角色:構建Web內容" class="phphistorical_Version2_mids_title">HTML的角色:構建Web內容</a><span class="Articlelist_txts_time">Apr 11, 2025 am 12:12 AM</span><p class="Articlelist_txts_p">HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796793634.html" title="HTML和代碼:仔細觀察術語" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174424853215422.jpg?x-oss-process=image/resize,p_40" alt="HTML和代碼:仔細觀察術語" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796793634.html" title="HTML和代碼:仔細觀察術語" class="phphistorical_Version2_mids_title">HTML和代碼:仔細觀察術語</a><span class="Articlelist_txts_time">Apr 10, 2025 am 09:28 AM</span><p class="Articlelist_txts_p">htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代碼” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代碼”代碼“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796793129.html" title="HTML,CSS和JavaScript:Web開發人員的基本工具" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174412873346901.jpg?x-oss-process=image/resize,p_40" alt="HTML,CSS和JavaScript:Web開發人員的基本工具" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796793129.html" title="HTML,CSS和JavaScript:Web開發人員的基本工具" class="phphistorical_Version2_mids_title">HTML,CSS和JavaScript:Web開發人員的基本工具</a><span class="Articlelist_txts_time">Apr 09, 2025 am 12:12 AM</span><p class="Articlelist_txts_p">HTML、CSS和JavaScript是Web開發的三大支柱。 1.HTML定義網頁結構,使用標籤如、等。 2.CSS控製網頁樣式,使用選擇器和屬性如color、font-size等。 3.JavaScript實現動態效果和交互,通過事件監聽和DOM操作。</p></div><div class="phphistorical_Version2_mids"><a href="https://m.php.cn/zh-tw/faq/1796792987.html" title="HTML,CSS和JavaScript的角色:核心職責" class="phphistorical_Version2_mids_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/article/001/253/068/174411031220217.jpg?x-oss-process=image/resize,p_40" alt="HTML,CSS和JavaScript的角色:核心職責" src="/static/imghw/default1.png" /></a><a href="https://m.php.cn/zh-tw/faq/1796792987.html" title="HTML,CSS和JavaScript的角色:核心職責" class="phphistorical_Version2_mids_title">HTML,CSS和JavaScript的角色:核心職責</a><span class="Articlelist_txts_time">Apr 08, 2025 pm 07:05 PM</span><p class="Articlelist_txts_p">HTML定義網頁結構,CSS負責樣式和佈局,JavaScript賦予動態交互。三者在網頁開發中各司其職,共同構建豐富多彩的網站。</p></div></div><a href="https://m.php.cn/zh-tw/web-designer.html" class="phpgenera_Details_mainL4_botton"><span>See all articles</span><img class="lazy" data-src="/static/imghwm/down_right.png" src="/static/imghw/default1.png" alt="" /></a></div><ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-6t+ed+2i-1n-4w" data-ad-client="ca-pub-5902227090019525" data-ad-slot="8966999616"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><div class="AI_ToolDetails_main4sR"><div class="phpgenera_Details_mainR3"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="/static/imghwm/hottools2.png" src="/static/imghw/default1.png" alt="" /><h2>熱AI工具</h2></div><div class="phpgenera_Details_mainR3_bottom"><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/undresserai-undress" title="Undresser.AI Undress"class="phpmain_tab2_mids_title"><h3>Undresser.AI Undress</h3></a><p>人工智慧驅動的應用程序,用於創建逼真的裸體照片</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/ai-clothes-remover" title="AI Clothes Remover"class="phpmain_tab2_mids_title"><h3>AI Clothes Remover</h3></a><p>用於從照片中去除衣服的線上人工智慧工具。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/undress-ai-tool" title="Undress AI Tool"class="phpmain_tab2_mids_title"><h3>Undress AI Tool</h3></a><p>免費脫衣圖片</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/clothoffio" title="Clothoff.io"class="phpmain_tab2_mids_title"><h3>Clothoff.io</h3></a><p>AI脫衣器</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/ai-hentai-generator" title="AI Hentai Generator" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173405034393877.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Hentai Generator" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/ai-hentai-generator" title="AI Hentai Generator"class="phpmain_tab2_mids_title"><h3>AI Hentai Generator</h3></a><p>免費產生 AI 無盡。</p></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/ai">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR4"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="/static/imghwm/hotarticle2.png" src="/static/imghw/default1.png" alt="" /><h2>熱門文章</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/1796780570.html" title="R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>4 週前</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/1796780641.html" title="R.E.P.O.最佳圖形設置" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.最佳圖形設置</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>4 週前</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/1796785841.html" title="刺客信條陰影:貝殼謎語解決方案" class="phpgenera_Details_mainR4_bottom_title">刺客信條陰影:貝殼謎語解決方案</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>2 週前</span><span>ByDDD</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/1796780520.html" title="R.E.P.O.如果您聽不到任何人,如何修復音頻" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O.如果您聽不到任何人,如何修復音頻</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>4 週前</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/1796779766.html" title="WWE 2K25:如何解鎖Myrise中的所有內容" class="phpgenera_Details_mainR4_bottom_title">WWE 2K25:如何解鎖Myrise中的所有內容</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 個月前</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/article.html">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR3"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="/static/imghwm/hottools2.png" src="/static/imghw/default1.png" alt="" /><h2>熱工具</h2></div><div class="phpgenera_Details_mainR3_bottom"><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1579" title="SecLists" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/008/169442209227215.jpg" src="/static/imghw/default1.png" alt="SecLists" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1579" title="SecLists" class="phpmain_tab2_mids_title"><h3>SecLists</h3></a><p>SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/toolset/development-tools/660" title="Atom編輯器mac版下載" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/001/58ed8cfa94c1a582.jpg" src="/static/imghw/default1.png" alt="Atom編輯器mac版下載" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/toolset/development-tools/660" title="Atom編輯器mac版下載" class="phpmain_tab2_mids_title"><h3>Atom編輯器mac版下載</h3></a><p>最受歡迎的的開源編輯器</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1575" title="DVWA" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/005/169233952150073.png" src="/static/imghw/default1.png" alt="DVWA" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1575" title="DVWA" class="phpmain_tab2_mids_title"><h3>DVWA</h3></a><p>Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1557" title="mPDF" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/003/169206948656118.png" src="/static/imghw/default1.png" alt="mPDF" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1557" title="mPDF" class="phpmain_tab2_mids_title"><h3>mPDF</h3></a><p>mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1545" title="SAP NetWeaver Server Adapter for Eclipse" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="https://img.php.cn/upload/manual/000/000/007/169165990824460.png" src="/static/imghw/default1.png" alt="SAP NetWeaver Server Adapter for Eclipse" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/toolset/development-tools/1545" title="SAP NetWeaver Server Adapter for Eclipse" class="phpmain_tab2_mids_title"><h3>SAP NetWeaver Server Adapter for Eclipse</h3></a><p>將Eclipse與SAP NetWeaver應用伺服器整合。</p></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/ai">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR4"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" class="lazy" data-src="/static/imghwm/hotarticle2.png" src="/static/imghw/default1.png" alt="" /><h2>熱門話題</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/gmailyxdlrkzn" title="gmail信箱登陸入口在哪裡" class="phpgenera_Details_mainR4_bottom_title">gmail信箱登陸入口在哪裡</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/eyess.png" src="/static/imghw/default1.png" alt="" /><span>7517</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/tiezi.png" src="/static/imghw/default1.png" alt="" /><span>15</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/cakephp-tutor" title="CakePHP 教程" class="phpgenera_Details_mainR4_bottom_title">CakePHP 教程</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/eyess.png" src="/static/imghw/default1.png" alt="" /><span>1378</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/tiezi.png" src="/static/imghw/default1.png" alt="" /><span>52</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/steamdzhmcssmgs" title="steam的賬戶名稱是什麼格式" class="phpgenera_Details_mainR4_bottom_title">steam的賬戶名稱是什麼格式</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/eyess.png" src="/static/imghw/default1.png" alt="" /><span>79</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/tiezi.png" src="/static/imghw/default1.png" alt="" /><span>11</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/winactivationkeyper" title="win11激活密鑰永久" class="phpgenera_Details_mainR4_bottom_title">win11激活密鑰永久</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/eyess.png" src="/static/imghw/default1.png" alt="" /><span>53</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/tiezi.png" src="/static/imghw/default1.png" alt="" /><span>19</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/newyorktimesdailybrief" title="NYT連接提示和答案" class="phpgenera_Details_mainR4_bottom_title">NYT連接提示和答案</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/eyess.png" src="/static/imghw/default1.png" alt="" /><span>21</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img class="lazy" data-src="/static/imghwm/tiezi.png" src="/static/imghw/default1.png" alt="" /><span>66</span></div></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/faq/zt">顯示更多</a></div></div></div></div></main><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="5027754603"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><footer><div class="footer"><div class="footertop"><img src="/static/imghwm/logo.png" alt=""><p>公益線上PHP培訓,幫助PHP學習者快速成長!</p></div><div class="footermid"><a href="https://m.php.cn/zh-tw/about/us.html">關於我們</a><a href="https://m.php.cn/zh-tw/about/disclaimer.html">免責聲明</a><a href="https://m.php.cn/zh-tw/update/article_0_1.html">Sitemap</a></div><div class="footerbottom"><p> © php.cn All rights reserved </p></div></div></footer><script>isLogin = 0;</script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script><script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script><link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css' type='text/css' media='all'/><script type='text/javascript' src='/static/js/viewer.min.js?1'></script><script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="https://tongji.php.cn/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '9']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><script> jQuery.fn.wait = function (func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = this.selector, //选择器 _iIntervalID; //定时器id if( this.length ){ //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function() { if(!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if( _self.length ) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $("table.syntaxhighlighter").wait(function() { $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>"); }); $(document).on("click", ".cnblogs_code_footer",function(){ $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide(); }); $('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}}); </script><script>// 通用函数,用于显示或隐藏元素 function toggleElementsDisplay(className, show) { const elements = document.getElementsByClassName(className); for (let i = 0; i < elements.length; i++) { elements[i].style.display = show ? "block" : "none"; } } // 页面加载完成后执行的主函数 document.addEventListener("DOMContentLoaded", () => { // 1. 绑定菜单按钮事件 const bindMenuEvents = () => { const toggleDisplay = (className, show, eventId) => { const element = document.getElementById(eventId); if (element) { element.addEventListener("click", (event) => { event.preventDefault(); toggleElementsDisplay(className, show); }); } }; toggleDisplay("m_editormain12main", true, "fixed_tab_img"); toggleDisplay("m_editormain12main", false, "fixed_tab_topi"); toggleDisplay("m_editormain12main", false, "fixed_tab_close"); toggleDisplay("m_menu", true, "lan1sp"); toggleDisplay("m_menu", false, "m_editormain12main_topi_sp"); toggleDisplay("m_menu_lang", true, "lan1"); toggleDisplay("m_menu_lang", false, "m_editormain12main_topi_lan"); }; // 2. 绑定滚动链接事件 const bindScrollLinks = () => { const titleList = document.getElementById("fixed_tab_titlelist"); const menuMain = document.getElementsByClassName("m_editormain12main")[0]; const links = document.querySelectorAll('.fixed_tab_a'); links.forEach(linkElement => { if (linkElement) { linkElement.addEventListener("click", async (e) => { e.preventDefault(); e.stopPropagation(); // 先隐藏菜单 if (menuMain) menuMain.style.display = "none"; if (titleList) titleList.style.display = "none"; // 获取目标元素的 ID const targetId = linkElement.getAttribute('href').substring(1); const targetElement = document.getElementById(targetId); // 等待 DOM 更新 await new Promise(resolve => requestAnimationFrame(resolve)); // 滚动到目标位置 if (targetElement) { targetElement.scrollIntoView({ behavior: "smooth", block: "start" }); } }); } }); }; // 3. 绑定关闭按钮事件 const bindCloseButton = () => { const closeButton = document.querySelector(".phpgenera_Details_mainR1_close"); const container = document.querySelector(".phpgenera_Details_mainR1"); if (closeButton && container) { closeButton.addEventListener("click", (event) => { event.preventDefault(); container.style.display = "none"; }); } }; // 4. 初始化菜单交互功能 const initMenuInteraction = () => { const menuGroupElements = document.querySelectorAll('.layui-menu-item-group'); menuGroupElements.forEach(menuItem => { menuItem.addEventListener('click', function(event) { if (event.target.closest('.m_menusnames')) { return; } this.classList.toggle('layui-menu-item-down'); this.classList.toggle('layui-menu-item-up'); const subMenuContainer = this.querySelector('.m_menusnames'); const icon = this.querySelector('.layui-icon'); if (subMenuContainer && icon) { if (this.classList.contains('layui-menu-item-down')) { subMenuContainer.style.display = 'block'; icon.classList.remove('layui-icon-down'); icon.classList.add('layui-icon-up'); } else { subMenuContainer.style.display = 'none'; icon.classList.remove('layui-icon-up'); icon.classList.add('layui-icon-down'); } } }); }); }; // 5. 初始化 layui 功能 const initLayui = () => { if (typeof layui !== 'undefined') { layui.use(function () { var util = layui.util; if (util && util.fixbar) { util.fixbar({ on: { mouseenter: function (type) { if (layer && layer.tips) { layer.tips(type, this, { tips: 4, fixed: true, }); } }, mouseleave: function (type) { if (layer && layer.closeAll) { layer.closeAll("tips"); } }, }, }); } }); } }; // 执行所有初始化函数 bindMenuEvents(); bindScrollLinks(); bindCloseButton(); initMenuInteraction(); initLayui(); }); </script></body></html>