首页  >  文章  >  web前端  >  HTML基础内容详解

HTML基础内容详解

巴扎黑
巴扎黑原创
2017-04-15 09:05:402373浏览

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><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><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><body>标签</h1> <h3>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>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>3.特殊符号</h3> <pre class="brush:php;toolbar:false">"    &quot; < &lt; >    &gt; 空格  ©    &copy; &    &amp; ¥    &yen; £    &pound;</pre> <h3>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>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>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>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>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>HTML简介</h1> <h3>什么是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>什么是标签</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>什么是标签属性</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>HTML5基本结构</h3> <pre class="brush:php;toolbar:false"><!DOCTYPE HTML> <html>     <head>     </head>     <body>     </body> </html></pre> <h3>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><head>标签</h1> <h3><title></h3> <p>显示在浏览器的标题栏</p> <h3><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><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><body>标签</h1> <h3>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>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>3.特殊符号</h3> <pre class="brush:php;toolbar:false">"    &quot; < &lt; >    &gt; 空格  ©    &copy; &    &amp; ¥    &yen; £    &pound;</pre> <h3>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>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>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>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>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="nphpQianMsg"><div class="clear"></div></div><div class="nphpQianSheng"><span>声明:</span><div>本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn</div></div></div><div class="nphpSytBox"><span>上一篇:<a class="dBlack" title="Html实现动态显示颜色块的报表效果的案例代码" href="http://m.php.cn/zh/faq/360361.html">Html实现动态显示颜色块的报表效果的案例代码</a></span><span>下一篇:<a class="dBlack" title="HTML 表单和输入" href="http://m.php.cn/zh/faq/360398.html">HTML 表单和输入</a></span></div><div class="nphpSytBox2"><div class="nphpZbktTitle"><h2>相关文章</h2><em><a href="http://m.php.cn/zh/article.html" class="bBlack"><i>查看更多</i><b></b></a></em><div class="clear"></div></div><ul class="nphpXgwzList"><li><b></b><a href="http://m.php.cn/zh/faq/348757.html" title="Html小知识总结" class="aBlack">Html小知识总结</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/zh/faq/348804.html" title="如何快速学习HTML" class="aBlack">如何快速学习HTML</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/zh/faq/348873.html" title="html xhtml xml的区别" class="aBlack">html xhtml xml的区别</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/zh/faq/348884.html" title="src与href属性的区别" class="aBlack">src与href属性的区别</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/zh/faq/348902.html" title="关于HTML5和CSS替换使用" class="aBlack">关于HTML5和CSS替换使用</a><div class="clear"></div></li></ul></div></div><div class="nphpFoot"><div class="nphpFootBg"><ul class="nphpFootMenu"><li><a href="http://m.php.cn/zh/"><b class="icon1"></b><p>首页</p></a></li><li><a href="http://m.php.cn/zh/course.html"><b class="icon2"></b><p>课程</p></a></li><li><a href="http://m.php.cn/zh/wenda.html"><b class="icon4"></b><p>问答</p></a></li><li><a href="http://m.php.cn/zh/login"><b class="icon5"></b><p>我的</p></a></li><div class="clear"></div></ul></div></div><div class="nphpYouBox" style="display: none;"><div class="nphpYouBg"><div class="nphpYouTitle"><span onclick="$('.nphpYouBox').hide()"></span><a href="http://m.php.cn/zh/"></a><div class="clear"></div></div><ul class="nphpYouList"><li><a href="http://m.php.cn/zh/"><b class="icon1"></b><span>首页</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/course.html"><b class="icon2"></b><span>课程</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/article.html"><b class="icon3"></b><span>文章</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/wenda.html"><b class="icon4"></b><span>问答</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/dic.html"><b class="icon6"></b><span>词典</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/course/type/99.html"><b class="icon7"></b><span>手册</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/xiazai/"><b class="icon8"></b><span>下载</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/zh/faq/zt" title="专题"><b class="icon12"></b><span>专题</span><div class="clear"></div></a></li><div class="clear"></div></ul></div></div><div class="nphpDing" style="display: none;"><div class="nphpDinglogo"><a href="http://m.php.cn/zh/"></a></div><div class="nphpNavIn1"><div class="swiper-container nphpNavSwiper1"><div class="swiper-wrapper"><div class="swiper-slide"><a href="http://m.php.cn/zh/" >首页</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/article.html" class="hover">文章</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/wenda.html" >问答</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/course.html" >课程</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/faq/zt" >专题</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/xiazai" >下载</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/game" >手游</a></div><div class="swiper-slide"><a href="http://m.php.cn/zh/dic.html" >词典</a></div><div class="clear"></div></div></div><div class="langadivs" ><a href="javascript:;" class="bg4 bglanguage"></a><div class="langadiv" ><a onclick="javascript:setlang('zh-cn');" class="language course-right-orders chooselan " href="javascript:;"><span>简体中文</span><span>(ZH-CN)</span></a><a onclick="javascript:setlang('en');" class="language course-right-orders chooselan " href="javascript:;"><span>English</span><span>(EN)</span></a><a onclick="javascript:setlang('zh-tw');" class="language course-right-orders chooselan " href="javascript:;"><span>繁体中文</span><span>(ZH-TW)</span></a><a onclick="javascript:setlang('ja');" class="language course-right-orders chooselan " href="javascript:;"><span>日本語</span><span>(JA)</span></a><a onclick="javascript:setlang('ko');" class="language course-right-orders chooselan " href="javascript:;"><span>한국어</span><span>(KO)</span></a><a onclick="javascript:setlang('ms');" class="language course-right-orders chooselan " href="javascript:;"><span>Melayu</span><span>(MS)</span></a><a onclick="javascript:setlang('fr');" class="language course-right-orders chooselan " href="javascript:;"><span>Français</span><span>(FR)</span></a><a onclick="javascript:setlang('de');" class="language course-right-orders chooselan " href="javascript:;"><span>Deutsch</span><span>(DE)</span></a></div></div><script> var swiper = new Swiper('.nphpNavSwiper1', { slidesPerView : 'auto', observer: true,//修改swiper自己或子元素时,自动初始化swiper observeParents: true,//修改swiper的父元素时,自动初始化swiper }); </script></div></div><!--顶部导航 end--><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></div><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>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></body></html>