search
HomeWeb Front-endHTML TutorialHTML基础内容详解
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>The above is the detailed content of HTML基础内容详解. For more information, please follow other related articles on the PHP Chinese website!</p></div><div class="wzconShengming_sp"><div class="bzsmdiv_sp">Statement</div><div>The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact 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">Related Article<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="" 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/000/000/024/62e8f68c61709797.jpg" alt="HTML超文本标记语言--超在那里?(文档分析)" src="/static/imghw/default1.png" /></a><a href="" title="HTML超文本标记语言--超在那里?(文档分析)" class="phphistorical_Version2_mids_title">HTML超文本标记语言--超在那里?(文档分析)</a><span class="Articlelist_txts_time">Aug 02, 2022 pm 06:04 PM</span><p class="Articlelist_txts_p">本篇文章带大家了解一下HTML(超文本标记语言),介绍一下HTML的本质,HTML文档的结构、HTML文档的基本标签和图像标签、列表、表格标签、媒体元素、表单,希望对大家有所帮助!</p></div><div class="phphistorical_Version2_mids"><a href="" title="html和css算编程语言吗" 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/202209/21/2022092115564549223.jpg" alt="html和css算编程语言吗" src="/static/imghw/default1.png" /></a><a href="" title="html和css算编程语言吗" class="phphistorical_Version2_mids_title">html和css算编程语言吗</a><span class="Articlelist_txts_time">Sep 21, 2022 pm 04:09 PM</span><p class="Articlelist_txts_p">不算。html是一种用来告知浏览器如何组织页面的标记语言,而CSS是一种用来表现HTML或XML等文件样式的样式设计语言;html和css不具备很强的逻辑性和流程控制功能,缺乏灵活性,且html和css不能按照人类的设计对一件工作进行重复的循环,直至得到让人类满意的答案。</p></div><div class="phphistorical_Version2_mids"><a href="" title="web前端笔试题库之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/000/000/024/6260d5be6235f375.jpg" alt="web前端笔试题库之HTML篇" src="/static/imghw/default1.png" /></a><a href="" title="web前端笔试题库之HTML篇" class="phphistorical_Version2_mids_title">web前端笔试题库之HTML篇</a><span class="Articlelist_txts_time">Apr 21, 2022 am 11:56 AM</span><p class="Articlelist_txts_p">总结了一些web前端面试(笔试)题分享给大家,本篇文章就先给大家分享HTML部分的笔试题(附答案),大家可以自己做做,看看能答对几个!</p></div><div class="phphistorical_Version2_mids"><a href="" title="HTML5中画布标签是什么" 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/202205/18/2022051816543362227.jpg" alt="HTML5中画布标签是什么" src="/static/imghw/default1.png" /></a><a href="" title="HTML5中画布标签是什么" class="phphistorical_Version2_mids_title">HTML5中画布标签是什么</a><span class="Articlelist_txts_time">May 18, 2022 pm 04:55 PM</span><p class="Articlelist_txts_p">HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。</p></div><div class="phphistorical_Version2_mids"><a href="" title="总结HTML中a标签的使用方法及跳转方式" 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/202208/05/2022080509181566289.jpg" alt="总结HTML中a标签的使用方法及跳转方式" src="/static/imghw/default1.png" /></a><a href="" title="总结HTML中a标签的使用方法及跳转方式" class="phphistorical_Version2_mids_title">总结HTML中a标签的使用方法及跳转方式</a><span class="Articlelist_txts_time">Aug 05, 2022 am 09:18 AM</span><p class="Articlelist_txts_p">本文给大家总结介绍a标签使用方法和跳转方式,希望对大家有所帮助!</p></div><div class="phphistorical_Version2_mids"><a href="" title="html5废弃了哪个列表标签" 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/202206/01/2022060118010096424.jpg" alt="html5废弃了哪个列表标签" src="/static/imghw/default1.png" /></a><a href="" title="html5废弃了哪个列表标签" class="phphistorical_Version2_mids_title">html5废弃了哪个列表标签</a><span class="Articlelist_txts_time">Jun 01, 2022 pm 06:32 PM</span><p class="Articlelist_txts_p">html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。</p></div><div class="phphistorical_Version2_mids"><a href="" title="html中document是什么" 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/202206/17/2022061715493574728.jpg" alt="html中document是什么" src="/static/imghw/default1.png" /></a><a href="" title="html中document是什么" class="phphistorical_Version2_mids_title">html中document是什么</a><span class="Articlelist_txts_time">Jun 17, 2022 pm 04:18 PM</span><p class="Articlelist_txts_p">在html中,document是文档对象的意思,代表浏览器窗口的文档;document对象是window对象的子对象,所以可通过“window.document”属性对其进行访问,每个载入浏览器的HTML文档都会成为Document对象。</p></div><div class="phphistorical_Version2_mids"><a href="" title="html5支持boolean值属性吗" 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/202204/22/2022042216453531093.jpg" alt="html5支持boolean值属性吗" src="/static/imghw/default1.png" /></a><a href="" title="html5支持boolean值属性吗" class="phphistorical_Version2_mids_title">html5支持boolean值属性吗</a><span class="Articlelist_txts_time">Apr 22, 2022 pm 04:56 PM</span><p class="Articlelist_txts_p">html5支持boolean值属性;boolean值属性指是属性值为true或者false的属性,如input元素中的disabled属性,不使用该属性表示值为flase,不禁用元素,使用该属性可以不设置属性值表示值为true,禁用元素。</p></div></div><a href="https://m.php.cn/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>Hot AI Tools</h2></div><div class="phpgenera_Details_mainR3_bottom"><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/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/ai/undresserai-undress" title="Undresser.AI Undress"class="phpmain_tab2_mids_title"><h3>Undresser.AI Undress</h3></a><p>AI-powered app for creating realistic nude photos</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/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/ai/ai-clothes-remover" title="AI Clothes Remover"class="phpmain_tab2_mids_title"><h3>AI Clothes Remover</h3></a><p>Online AI tool for removing clothes from photos.</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/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/ai/undress-ai-tool" title="Undress AI Tool"class="phpmain_tab2_mids_title"><h3>Undress AI Tool</h3></a><p>Undress images for free</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/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/ai/clothoffio" title="Clothoff.io"class="phpmain_tab2_mids_title"><h3>Clothoff.io</h3></a><p>AI clothes remover</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/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/ai/ai-hentai-generator" title="AI Hentai Generator"class="phpmain_tab2_mids_title"><h3>AI Hentai Generator</h3></a><p>Generate AI Hentai for free.</p></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/ai">Show More</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>Hot Article</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/1796780570.html" title="R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>2 weeks ago</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/1796773439.html" title="Repo: How To Revive Teammates" class="phpgenera_Details_mainR4_bottom_title">Repo: How To Revive Teammates</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>4 weeks ago</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/1796774171.html" title="Hello Kitty Island Adventure: How To Get Giant Seeds" class="phpgenera_Details_mainR4_bottom_title">Hello Kitty Island Adventure: How To Get Giant Seeds</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>4 weeks ago</span><span>By尊渡假赌尊渡假赌尊渡假赌</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/1796775427.html" title="How Long Does It Take To Beat Split Fiction?" class="phpgenera_Details_mainR4_bottom_title">How Long Does It Take To Beat Split Fiction?</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>3 weeks ago</span><span>ByDDD</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/1796775336.html" title="R.E.P.O. Save File Location: Where Is It & How to Protect It?" class="phpgenera_Details_mainR4_bottom_title">R.E.P.O. Save File Location: Where Is It & How to Protect It?</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>3 weeks ago</span><span>ByDDD</span></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/article.html">Show More</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>Hot Tools</h2></div><div class="phpgenera_Details_mainR3_bottom"><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/toolset/development-tools/1492" title="EditPlus Chinese cracked version" 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/5e21527e79622256.png" src="/static/imghw/default1.png" alt="EditPlus Chinese cracked version" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/toolset/development-tools/1492" title="EditPlus Chinese cracked version" class="phpmain_tab2_mids_title"><h3>EditPlus Chinese cracked version</h3></a><p>Small size, syntax highlighting, does not support code prompt function</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/toolset/development-tools/505" title="Dreamweaver Mac version" 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/58d36dab93a95387.png" src="/static/imghw/default1.png" alt="Dreamweaver Mac version" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/toolset/development-tools/505" title="Dreamweaver Mac version" class="phpmain_tab2_mids_title"><h3>Dreamweaver Mac version</h3></a><p>Visual web development tools</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/toolset/development-tools/502" title="ZendStudio 13.5.1 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/58d3631514435840.png" src="/static/imghw/default1.png" alt="ZendStudio 13.5.1 Mac" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/toolset/development-tools/502" title="ZendStudio 13.5.1 Mac" class="phpmain_tab2_mids_title"><h3>ZendStudio 13.5.1 Mac</h3></a><p>Powerful PHP integrated development environment</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/toolset/development-tools/500" title="SublimeText3 Mac version" 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/58d34035e2757995.png" src="/static/imghw/default1.png" alt="SublimeText3 Mac version" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/toolset/development-tools/500" title="SublimeText3 Mac version" class="phpmain_tab2_mids_title"><h3>SublimeText3 Mac version</h3></a><p>God-level code editing software (SublimeText3)</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/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/toolset/development-tools/1557" title="mPDF" class="phpmain_tab2_mids_title"><h3>mPDF</h3></a><p>mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),</p></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/ai">Show More</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>Hot Topics</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/gmailyxdlrkzn" title="Where is the login entrance for gmail email?" class="phpgenera_Details_mainR4_bottom_title">Where is the login entrance for gmail email?</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>7322</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>9</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/java-tutorial" title="Java Tutorial" class="phpgenera_Details_mainR4_bottom_title">Java Tutorial</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>1625</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>14</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/cakephp-tutor" title="CakePHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">CakePHP Tutorial</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>1350</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>46</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/laravel-tutori" title="Laravel Tutorial" class="phpgenera_Details_mainR4_bottom_title">Laravel Tutorial</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>1262</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>25</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/faq/php-tutorial" title="PHP Tutorial" class="phpgenera_Details_mainR4_bottom_title">PHP Tutorial</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>1209</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>29</span></div></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/faq/zt">Show More</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>Public welfare online PHP training,Help PHP learners grow quickly!</p></div><div class="footermid"><a href="https://m.php.cn/about/us.html">About us</a><a href="https://m.php.cn/about/disclaimer.html">Disclaimer</a><a href="https://m.php.cn/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');});}}); // 通用函数,用于显示或隐藏元素 function toggleElementsDisplay(className, show) { const elements = document.getElementsByClassName(className); for (let i = 0; i < elements.length; i++) { elements[i].style.display = show ? "block" : "none"; } } // 绑定事件监听器 function bindEventListeners() { const toggleDisplay = (className, show, eventId) => { document.getElementById(eventId).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"); // 控制 m_menu 的显示和隐藏 toggleDisplay("m_menu", true, "lan1sp"); toggleDisplay("m_menu", false, "m_editormain12main_topi_sp"); // 控制 m_menu_lang 的显示和隐藏 toggleDisplay("m_menu_lang", true, "lan1"); toggleDisplay("m_menu_lang", false, "m_editormain12main_topi_lan"); } // 在页面加载完成后绑定事件监听器 window.onload = bindEventListeners; layui.use(function () { var util = layui.util; util.fixbar({ on: { mouseenter: function (type) { layer.tips(type, this, { tips: 4, fixed: true, }); }, mouseleave: function (type) { layer.closeAll("tips"); }, }, }); }); // 获取关闭按钮 const closeButton = document.querySelector(".phpgenera_Details_mainR1_close"); // 获取容器元素 const container = document.querySelector(".phpgenera_Details_mainR1"); // 添加点击事件监听器 closeButton.addEventListener("click", (event) => { event.preventDefault(); // 阻止默认的<a>点击行为 container.style.display = "none"; // 隐藏容器 }); document.addEventListener("DOMContentLoaded", () => { // 动态获取所有滚动链接及隐藏目标元素 const links = [{ linkId: "fixed_tab_a1", targetId: "article_main_title1", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, { linkId: "fixed_tab_a2", targetId: "article_main_title2", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, { linkId: "fixed_tab_a3", targetId: "article_main_title3", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, { linkId: "fixed_tab_a4", targetId: "article_main_title4", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, ]; links.forEach(({ linkId, targetId, hideElementId }) => { const linkElement = document.getElementById(linkId); const targetElement = document.getElementById(targetId); const hideElement = document.getElementById(hideElementId); if (linkElement && targetElement) { linkElement.addEventListener("click", (e) => { e.preventDefault(); // 阻止默认行为 // 隐藏指定元素 if (hideElement) { hideElement.style.display = "none"; // 也可以用其他方法隐藏,如 `visibility: hidden` } // 平滑滚动到目标元素 targetElement.scrollIntoView({ behavior: "smooth" }); }); } else { console.warn( `Link, target, or hide element not found: ${linkId}, ${targetId}, ${hideElementId}` ); } }); }); // 初始化菜单交互功能 document.addEventListener('DOMContentLoaded', function () { 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'); // 切换子菜单显示状态 if (subMenuContainer) { if (this.classList.contains('layui-menu-item-down')) { subMenuContainer.style.display = 'block'; this.querySelector('.layui-icon').classList.remove( 'layui-icon-down'); this.querySelector('.layui-icon').classList.add('layui-icon-up'); } else { subMenuContainer.style.display = 'none'; this.querySelector('.layui-icon').classList.remove('layui-icon-up'); this.querySelector('.layui-icon').classList.add('layui-icon-down'); } } }); }); }); </script></body></html>