整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          HTML ANSI(Windows-1252)參考手冊

          NSI(Windows-1252)

          ANSI 是 Windows 95 及其之前的 Windows 系統中默認的字符集。

          ANSI 也稱為 Windows-1252。


          重要提示

          ANSI 和 ISO-8859-1 非常相似,唯一的不同是在 32 個字符上。

          在 ANSI 中,從 128 到 159 的字符用于一些有用的字符,比如歐元符號。

          在 ISO-8859-1 中,這些字符映射為在 HTML 中不起作用的控制字符。

          許多 Web 開發者聲明 ISO-8859-1,并使用這 32 個值,就像它們使用的是 Windows-1252。

          由于這種常見的誤解,當 ISO-8859-1 被聲明時,瀏覽器將更改為 Windows-1252。這對以下文檔類型都適用:HTML4、HTML5 和 XHTML。


          ANSI 和 ASCII

          ANSI 的第一部分(實體編號 0-127)是原來的 ASCII 字符集。它包含數字、大小寫英文字母和一些特殊字符。

          如需深入了解 ASCII,請查看完整的 ASCII 參考手冊。


          ANSI 字符集

          字符編號實體名稱描述
          32空格(space)
          !33感嘆號(exclamation mark)
          "34"引號(quotation mark)
          #35數字符號(number sign)
          $36美元符號(dollar sign)
          %37百分比符號(percent sign)
          &38&& 符號(ampersand)
          '39撇號(apostrophe)
          (40左括號(left parenthesis)
          )41右括號(right parenthesis)
          *42星號(asterisk)
          +43加號(plus sign)
          ,44逗號(comma)
          -45連字符(hyphen-minus)
          .46句號(full stop)
          /47斜線(solidus)
          048數字 0(digit zero)
          149數字 1(digit one)
          250數字 2(digit two)
          351數字 3(digit three)
          452數字 4(digit four)
          553數字 5(digit five)
          654數字 6(digit six)
          755數字 7(digit seven)
          856數字 8(digit eight)
          957數字 9(digit nine)
          :58冒號(colon)
          ;59分號(semicolon)
          <60&lt;小于號(less-than sign)
          =61等于號(equals sign)
          >62&gt;大于號(greater-than sign)
          ?63問號(question mark)
          @64@ 符號(commercial at)
          A65拉丁文大寫字母 A
          B66拉丁文大寫字母 B
          C67拉丁文大寫字母 C
          D68拉丁文大寫字母 D
          E69拉丁文大寫字母 E
          F70拉丁文大寫字母 F
          G71拉丁文大寫字母 G
          H72拉丁文大寫字母 H
          I73拉丁文大寫字母 I
          J74拉丁文大寫字母 J
          K75拉丁文大寫字母 K
          L76拉丁文大寫字母 L
          M77拉丁文大寫字母 M
          N78拉丁文大寫字母 N
          O79拉丁文大寫字母 O
          P80拉丁文大寫字母 P
          Q81拉丁文大寫字母 Q
          R82拉丁文大寫字母 R
          S83拉丁文大寫字母 S
          T84拉丁文大寫字母 T
          U85拉丁文大寫字母 U
          V86拉丁文大寫字母 V
          W87拉丁文大寫字母 W
          X88拉丁文大寫字母 X
          Y89拉丁文大寫字母 Y
          Z90拉丁文大寫字母 Z
          [91左方括號(left square bracket)
          \92反斜線(reverse solidus)
          ]93右方括號(right square bracket)
          ^94插入符號(circumflex accent)
          _95下劃線(low line)
          `96重音符(grave accent)
          a97拉丁文小寫字母 a
          b98拉丁文小寫字母 b
          c99拉丁文小寫字母 c
          d100拉丁文小寫字母 d
          e101拉丁文小寫字母 e
          f102拉丁文小寫字母 f
          g103拉丁文小寫字母 g
          h104拉丁文小寫字母 h
          i105拉丁文小寫字母 i
          j106拉丁文小寫字母 j
          k107拉丁文小寫字母 k
          l108拉丁文小寫字母 l
          m109拉丁文小寫字母 m
          n110拉丁文小寫字母 n
          o111拉丁文小寫字母 o
          p112拉丁文小寫字母 p
          q113拉丁文小寫字母 q
          r114拉丁文小寫字母 r
          s115拉丁文小寫字母 s
          t116拉丁文小寫字母 t
          u117拉丁文小寫字母 u
          v118拉丁文小寫字母 v
          w119拉丁文小寫字母 w
          x120拉丁文小寫字母 x
          y121拉丁文小寫字母 y
          z122拉丁文小寫字母 z
          {123左花括號(left curly bracket)
          |124豎線(vertical line)
          }125右花括號(right curly bracket)
          ~126波浪線(tilde)
          127未使用(NOT USED)
          128&euro;歐元符號(euro sign)
          129未使用(NOT USED)
          ?130&sbquo;下單引號(single low-9 quotation mark)
          ?131&fnof;帶鉤的拉丁文小寫字母 f
          ?132&bdquo;下雙引號(double low-9 quotation mark)
          133&hellip;水平省略號(horizontal ellipsis)
          ?134&dagger;劍號(dagger)
          ?135&Dagger;雙劍號(double dagger)
          ?136&circ;修飾字母抑揚音(modifier letter circumflex accent)
          137&permil;千分比符號(per mille sign)
          ?138&Scaron;帶有 caron 的拉丁文大寫字母 S
          ?139&lsaquo;左單角引號(single left-pointing angle quotation mark)
          ?140&OElig;拉丁文大寫連字 OE
          141未使用(NOT USED)
          ?142&Zcaron;帶有 caron 的拉丁文大寫字母 Z
          143未使用(NOT USED)
          144未使用(NOT USED)
          '145&lsquo;左單引號(left single quotation mark)
          '146&rsquo;右單引號(right single quotation mark)
          "147&ldquo;左雙引號(left double quotation mark)
          "148&rdquo;右雙引號(right double quotation mark)
          ?149&bull;著重號(bullet)
          150&ndash;短破折號/連字符(en dash)
          151&mdash;長破折號(em dash)
          ?152&tilde;小波浪線(small tilde)
          ?153&trade;貿易標記符號(trade mark sign)
          ?154&scaron;帶有 caron 的拉丁文小寫字母 s
          ?155&rsaquo;右單角引號(single right-pointing angle quotation mark)
          ?156&oelig;拉丁文小寫連字 oe
          157未使用(NOT USED)
          ?158&zcaron;帶有 caron 的拉丁文小寫字母 z
          ?159&Yuml;帶有分音符(diaeresis)的拉丁文大寫字母 Y
          160&nbsp;不換行空格(no-break space)
          ?161&iexcl;倒置感嘆號(inverted exclamation mark)
          162&cent;美分符號(cent sign)
          163&pound;英鎊符號(pound sign)
          ¤164&curren;貨幣符號(currency sign)
          165&yen;日元符號(yen sign)
          |166&brvbar;間斷的豎杠(broken bar)
          §167&sect;小節號(section sign)
          ¨168&uml;分音符號(diaeresis)
          ?169&copy;版權所有(copyright sign)
          a170&ordf;陰性序數記號(feminine ordinal indicator)
          ?171&laquo;左雙角引號(left-pointing double angle quotation mark)
          ?172&not;否定符號(not sign)
          173&shy;軟連字符(soft hyphen)
          ?174&reg;注冊商標(registered sign)
          ˉ175&macr;長音符號(macron)
          °176&deg;度符號(degree sign)
          ±177&plusmn;加減號/正負號(plus-minus sign)
          2178&sup2;上標 2(superscript two)
          3179&sup3;上標 3(superscript three)
          180&acute;尖音符號(acute accent)
          μ181&micro;微米符號(micro sign)
          ?182&para;段落符號(pilcrow sign)
          ·183&middot;中間點(middle dot)
          ?184&cedil;變音符號(cedilla)
          1185&sup1;上標 1(superscript one)
          o186&ordm;陽性序數記號(masculine ordinal indicator)
          ?187&raquo;右雙角引號(right-pointing double angle quotation mark)
          ?188&frac14;1/4 分數(vulgar fraction one quarter)
          ?189&frac12;1/2 分數(vulgar fraction one half)
          ?190&frac34;3/4 分數(vulgar fraction three quarters)
          ?191&iquest;倒置問號(inverted question mark)
          à192&Agrave;帶有重音符號(grave)的拉丁文大寫字母 A
          á193&Aacute;帶有尖音符號(acute)的拉丁文大寫字母 A
          ?194&Acirc;帶有抑揚音符號(circumflex)的拉丁文大寫字母 A
          ?195&Atilde;帶有波浪線的拉丁文大寫字母 A
          ?196&Auml;帶有分音符(diaeresis)的拉丁文大寫字母 A
          ?197&Aring;帶有上圓圈的拉丁文大寫字母 A
          ?198&AElig;拉丁文大寫字母 AE
          ?199&Ccedil;帶有變音符號(cedilla)的拉丁文大寫字母 C
          è200&Egrave;帶有重音符號(grave)的拉丁文大寫字母 E
          é201&Eacute;帶有尖音符號(acute)的拉丁文大寫字母 E
          ê202&Ecirc;帶有抑揚符號(circumflex)的拉丁文大寫字母 E
          ?203&Euml;帶有分音符(diaeresis)的拉丁文大寫字母 E
          ì204&Igrave;帶有重音符號(grave)的拉丁文大寫字母 I
          í205&Iacute;帶有尖音符號(acute)的拉丁文大寫字母 I
          ?206&Icirc;帶有抑揚音符號(circumflex)的拉丁文大寫字母 I
          ?207&Iuml;帶有分音符(diaeresis)的拉丁文大寫字母 I
          D208&ETH;拉丁文大寫字母 Eth
          ?209&Ntilde;帶有波浪線的拉丁文大寫字母 N
          ò210&Ograve;帶有重音符號(grave)的拉丁文大寫字母 O
          ó211&Oacute;帶有尖音符號(acute)的拉丁文大寫字母 O
          ?212&Ocirc;帶有抑揚音符號(circumflex)的拉丁文大寫字母 O
          ?213&Otilde;帶有波浪線的拉丁文大寫字母 O
          ?214&Ouml;帶有分音符(diaeresis)的拉丁文大寫字母 O
          ×215&times;乘號(multiplication sign)
          ?216&Oslash;帶有刪除線的拉丁文大寫字母 O
          ù217&Ugrave;帶有重音符號(grave)的拉丁文大寫字母 U
          ú218&Uacute;帶有尖音符號(acute)的拉丁文大寫字母 U
          ?219&Ucirc;帶有抑揚音符號(circumflex)的拉丁文大寫字母 U
          ü220&Uuml;帶有分音符(diaeresis)的拉丁文大寫字母 U
          Y221&Yacute;帶有尖音符號(acute)的拉丁文大寫字母 Y
          T222&THORN;拉丁文大寫字母 Thorn
          ?223&szlig;拉丁文小寫字母 sharp s
          à224&agrave;帶有重音符號(grave)的拉丁文小寫字母 a
          á225&aacute;帶有尖音符號(acute)的拉丁文小寫字母 a
          a226&acirc;帶有抑揚音符號(circumflex)的拉丁文小寫字母 a
          ?227&atilde;帶有波浪線的拉丁文小寫字母 a
          ?228&auml;帶有分音符(diaeresis)的拉丁文小寫字母 a
          ?229&aring;帶有上圓圈的拉丁文小寫字母 a
          ?230&aelig;拉丁文小寫字母 ae
          ?231&ccedil;帶有變音符號(cedilla)的拉丁文小寫字母 c
          è232&egrave;帶有重音符號(grave)的拉丁文小寫字母 e
          é233&eacute;帶有尖音符號(acute)的拉丁文小寫字母 e
          ê234&ecirc;帶有抑揚音符號(circumflex)的拉丁文小寫字母 e
          ?235&euml;帶有分音符(diaeresis)的拉丁文小寫字母 e
          ì236&igrave;帶有重音符號(grave)的拉丁文小寫字母 i
          í237&iacute;帶有尖音符號(acute)的拉丁文小寫字母 i
          ?238&icirc;帶有抑揚音符號(circumflex)的拉丁文小寫字母 i
          ?239&iuml;帶有分音符(diaeresis)的拉丁文小寫字母 i
          e240&eth;拉丁文小寫字母 eth
          ?241&ntilde;帶有波浪線的拉丁文小寫字母 n
          ò242&ograve;帶有重音符號(grave)的拉丁文小寫字母 o
          ó243&oacute;帶有尖音符號(acute)的拉丁文小寫字母 o
          ?244&ocirc;帶有抑揚音符號(circumflex)的拉丁文小寫字母 o
          ?245&otilde;帶有波浪線的拉丁文小寫字母 o
          ?246&ouml;帶有分音符(diaeresis)的拉丁文小寫字母 o
          ÷247&divide;除號(division sign)
          ?248&oslash;帶有刪除線的拉丁文小寫字母 o
          ù249&ugrave;帶有重音符號(grave)的拉丁文小寫字母 u
          ú250&uacute;帶有尖音符號(acute)的拉丁文小寫字母 u
          ?251&ucirc;帶有抑揚音符號(circumflex)的拉丁文小寫字母 u
          ü252&uuml;帶有分音符(diaeresis)的拉丁文小寫字母 u
          y253&yacute;帶有尖音符號(acute)的拉丁文小寫字母 y
          t254&thorn;拉丁文小寫字母 thorn
          ?255&yuml;帶有分音符(diaeresis)的拉丁文小寫字母 y

          ANSI 控制字符

          ANSI 控制字符(00-31,加上 127)最初被設計用來控制諸如打印機和磁帶驅動器之類的硬件設備。

          控制字符(除了水平制表符、換行、回車之外)在 HTML 文檔中不起任何作用。

          字符編號描述
          NUL00空字符(null character)
          SOH01標題開始(start of header)
          STX02正文開始(start of text)
          ETX03正文結束(end of text)
          EOT04傳輸結束(end of transmission)
          ENQ05請求(enquiry)
          ACK06收到通知/響應(acknowledge)
          BEL07響鈴(bell)
          BS08退格(backspace)
          HT09水平制表符(horizontal tab)
          LF10換行(line feed)
          VT11垂直制表符(vertical tab)
          FF12換頁(form feed)
          CR13回車(carriage return)
          SO14不用切換(shift out)
          SI15啟用切換(shift in)
          DLE16數據鏈路轉義(data link escape)
          DC117設備控制 1(device control 1)
          DC218設備控制 2(device control 2)
          DC319設備控制 3(device control 3)
          DC420設備控制 4(device control 4)
          NAK21拒絕接收/無響應(negative acknowledge)
          SYN22同步空閑(synchronize)
          ETB23傳輸塊結束(end transmission block)
          CAN24取消(cancel)
          EM25已到介質末端/介質存儲已滿(end of medium)
          SUB26替補/替換(substitute)
          ESC27溢出/逃離/取消(escape)
          FS28文件分隔符(file separator)
          GS29組分隔符(group separator)
          RS30記錄分隔符(record separator)
          US31單元分隔符(unit separator)
          DEL127刪除(delete)

          如您還有不明白的可以在下面與我留言或是與我探討QQ群308855039,我們一起飛!

          譯自: https://medium.freecodecamp.org/for-your-first-html-code-lets-help-batman-write-a-love-letter-64c203b9360b

          作者: Kunal Sarkar

          譯者: MjSeven

          在一個美好的夜晚,你的肚子拒絕消化你在晚餐吃的大塊披薩,所以你不得不在睡夢中沖進洗手間。

          在浴室里,當你在思考為什么會發生這種情況時,你聽到一個來自通風口的低沉聲音:“嘿,我是蝙蝠俠。”

          這時,你會怎么做呢?

          在你恐慌并處于關鍵時刻之前,蝙蝠俠說:“我需要你的幫助。我是一個超級極客,但我不懂 HTML。我需要用 HTML 寫一封情書,你愿意幫助我嗎?”

          誰會拒絕蝙蝠俠的請求呢,對吧?所以讓我們用 HTML 來寫一封蝙蝠俠的情書。

          你的第一個 HTML 文件

          HTML 網頁與你電腦上的其它文件一樣。就同一個 .doc 文件以 MS Word 打開,.jpg 文件在圖像查看器中打開一樣,一個 .html 文件在瀏覽器中打開。

          那么,讓我們來創建一個 .html 文件。你可以在 Notepad 或其它任何編輯器中完成此任務,但我建議使用 VS Code。 在這里下載并安裝 VS Code 。它是免費的,也是我唯一喜歡的微軟產品。

          在系統中創建一個目錄,將其命名為 “HTML Practice”(不帶引號)。在這個目錄中,再創建一個名為 “Batman’s Love Letter”(不帶引號)的目錄,這將是我們的項目根目錄。這意味著我們所有與這個項目相關的文件都會在這里。

          打開 VS Code,按下 ctrl+n 創建一個新文件,按下 ctrl+s 保存文件。切換到 “Batman’s Love Letter” 文件夾并將其命名為 “loveletter.html”,然后單擊保存。

          現在,如果你在文件資源管理器中雙擊它,它將在你的默認瀏覽器中打開。我建議使用 Firefox 來進行 web 開發,但 Chrome 也可以。

          讓我們將這個過程與我們已經熟悉的東西聯系起來。還記得你第一次拿到電腦嗎?我做的第一件事是打開 MS Paint 并繪制一些東西。你在 Paint 中繪制一些東西并將其另存為圖像,然后你可以在圖像查看器中查看該圖像。之后,如果要再次編輯該圖像,你在 Paint 中重新打開它,編輯并保存它。

          我們目前的流程非常相似。正如我們使用 Paint 創建和編輯圖像一樣,我們使用 VS Code 來創建和編輯 HTML 文件。就像我們使用圖像查看器查看圖像一樣,我們使用瀏覽器來查看我們的 HTML 頁面。

          HTML 中的段落

          我們有一個空的 HTML 文件,以下是蝙蝠俠想在他的情書中寫的第一段。

          “After all the battles we fought together, after all the difficult times we saw together, and after all the good and bad moments we’ve been through, I think it’s time I let you know how I feel about you.”

          復制這些到 VS Code 中的 loveletter.html。單擊 “View -> Toggle Word Wrap (alt+z)” 自動換行。

          保存并在瀏覽器中打開它。如果它已經打開,單擊瀏覽器中的刷新按鈕。

          瞧!那是你的第一個網頁!

          我們的第一段已準備就緒,但這不是在 HTML 中編寫段落的推薦方法。我們有一種特定的方法讓瀏覽器知道一個文本是一個段落。

          如果你用 <p> 和 </p> 來包裹文本,那么瀏覽器將識別 <p> 和 </p> 中的文本是一個段落。我們這樣做:

          <p>After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.</p>

          通過在 <p> 和 </p>中編寫段落,你創建了一個 HTML 元素。一個網頁就是 HTML 元素的集合。

          讓我們首先來認識一些術語:<p> 是開始標簽,</p> 是結束標簽,“p” 是標簽名稱。元素開始和結束標簽之間的文本是元素的內容。

          “style” 屬性

          在上面,你將看到文本覆蓋屏幕的整個寬度。

          我們不希望這樣。沒有人想要閱讀這么長的行。讓我們設定段落寬度為 550px。

          我們可以通過使用元素的 style 屬性來實現。你可以在其 style 屬性中定義元素的樣式(例如,在我們的示例中為寬度)。以下行將在 p 元素上創建一個空樣式屬性:

          <p style="">...</p>

          你看到那個空的 "" 了嗎?這就是我們定義元素外觀的地方。現在我們要將寬度設置為 550px。我們這樣做:

          <p style="width:550px;">

          After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          我們將 width 屬性設置為 550px,用冒號 : 分隔,以分號 ; 結束。

          另外,注意我們如何將 <p> 和 </p> 放在單獨的行中,文本內容用一個制表符縮進。像這樣設置代碼使其更具可讀性。

          HTML 中的列表

          接下來,蝙蝠俠希望列出他所欽佩的人的一些優點,例如:

          You complete my darkness with your light. I love:

          - the way you see good in the worst things

          - the way you handle emotionally difficult situations

          - the way you look at Justice

          I have learned a lot from you. You have occupied a special place in my heart over time.

          這看起來很簡單。

          讓我們繼續,在 </p> 下面復制所需的文本:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love:

          - the way you see good in the worse

          - the way you handle emotionally difficult situations

          - the way you look at Justice

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          保存并刷新瀏覽器。



          哇!這里發生了什么,我們的列表在哪里?

          如果你仔細觀察,你會發現沒有顯示換行符。在代碼中我們在新的一行中編寫列表項,但這些項在瀏覽器中顯示在一行中。

          如果你想在 HTML(新行)中插入換行符,你必須使用 <br>。讓我們來使用 <br>,看看它長什么樣:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love: <br>

          - the way you see good in the worse <br>

          - the way you handle emotionally difficult situations <br>

          - the way you look at Justice <br>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          保存并刷新:



          好的,現在它看起來就像我們想要的那樣!

          另外,注意我們沒有寫一個 </br>。有些標簽不需要結束標簽(它們被稱為自閉合標簽)。

          還有一件事:我們沒有在兩個段落之間使用 <br>,但第二個段落仍然是從一個新行開始,這是因為 <p> 元素會自動插入換行符。

          我們使用純文本編寫列表,但是有兩個標簽可以供我們使用來達到相同的目的:<ul> and <li>。

          讓我們解釋一下名字的意思:ul 代表 無序列表(Unordered List),li 代表 列表項目(List Item)。讓我們使用它們來展示我們的列表:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love:

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          在復制代碼之前,注意差異部分:

          • 我們刪除了所有的 <br>,因為每個 <li> 會自動顯示在新行中
          • 我們將每個列表項包含在 <li> 和 </li> 之間
          • 我們將所有列表項的集合包裹在 <ul> 和 </ul> 之間
          • 我們沒有像 <p> 元素那樣定義 <ul> 元素的寬度。這是因為 <ul> 是 <p> 的子節點,<p> 已經被約束到 550px,所以 <ul> 不會超出這個范圍。

          讓我們保存文件并刷新瀏覽器以查看結果:



          你會立即注意到在每個列表項之前顯示了重點標志。我們現在不需要在每個列表項之前寫 “-”。

          經過仔細檢查,你會注意到最后一行超出 550px 寬度。這是為什么?因為 HTML 不允許 <ul> 元素出現在 <p> 元素中。讓我們將第一行和最后一行放在單獨的 <p> 元素中:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love:

          </p>

          <ul style="width:550px;">

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p style="width:550px;">

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          保存并刷新。

          注意,這次我們還定義了 <ul> 元素的寬度。那是因為我們現在已經將 <ul> 元素放在了 <p> 元素之外。

          定義情書中所有元素的寬度會變得很麻煩。我們有一個特定的元素用于此目的:<div> 元素。一個 <div> 元素就是一個通用容器,用于對內容進行分組,以便輕松設置樣式。

          讓我們用 <div> 元素包裝整個情書,并為其賦予寬度:550px 。

          <div style="width:550px;">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          棒極了,我們的代碼現在看起來簡潔多了。

          HTML 中的標題

          到目前為止,蝙蝠俠對結果很高興,他希望在情書上標題。他想寫一個標題: “Bat Letter”。當然,你已經看到這個名字了,不是嗎?:D

          你可以使用 <h1>、<h2>、<h3>、<h4>、<h5> 和 <h6> 標簽來添加標題,<h1> 是最大的標題和最主要的標題,<h6> 是最小的標題。



          讓我們在第二段之前使用 <h1> 做主標題和一個副標題:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          保存,刷新。



          HTML 中的圖像

          我們的情書尚未完成,但在繼續之前,缺少一件大事:蝙蝠俠標志。你見過是蝙蝠俠的東西但沒有蝙蝠俠的標志嗎?

          并沒有。

          所以,讓我們在情書中添加一個蝙蝠俠標志。

          在 HTML 中包含圖像就像在一個 Word 文件中包含圖像一樣。在 MS Word 中,你到 “菜單 -> 插入 -> 圖像 -> 然后導航到圖像位置為止 -> 選擇圖像 -> 單擊插入”。

          在 HTML 中,我們使用 <img> 標簽讓瀏覽器知道我們需要加載的圖像,而不是單擊菜單。我們在 src 屬性中寫入文件的位置和名稱。如果圖像在項目根目錄中,我們可以簡單地在 src 屬性中寫入圖像文件的名稱。

          在我們深入編碼之前,從 這里 下載蝙蝠俠標志。你可能希望裁剪圖像中的額外空白區域。復制項目根目錄中的圖像并將其重命名為 “bat-logo.jpeg”。

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          我們在第 3 行包含了 <img> 標簽。這個標簽也是一個自閉合的標簽,所以我們不需要寫 </img>。在 src 屬性中,我們給出了圖像文件的名稱。這個名稱應與圖像名稱完全相同,包括擴展名(.jpeg)及其大小寫。

          保存并刷新,查看結果。



          該死的!剛剛發生了什么?

          當使用 <img> 標簽包含圖像時,默認情況下,圖像將以其原始分辨率顯示。在我們的例子中,圖像比 550px 寬得多。讓我們使用 style 屬性定義它的寬度:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg" style="width:100%">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          你會注意到,這次我們定義寬度使用了 “%” 而不是 “px”。當我們在 “%” 中定義寬度時,它將占據父元素寬度的百分比。因此,100% 的 550px 將為我們提供 550px。

          保存并刷新,查看結果。



          太棒了!這讓蝙蝠俠的臉露出了羞澀的微笑 :)。

          HTML 中的粗體和斜體

          現在蝙蝠俠想在最后幾段中承認他的愛。他有以下文本供你用 HTML 編寫:

          “I have a confession to make

          It feels like my chest does have a heart. You make my heart beat. Your smile brings a smile to my face, your pain brings pain to my heart.

          I don’t show my emotions, but I think this man behind the mask is falling for you.”

          當閱讀到這里時,你會問蝙蝠俠:“等等,這是給誰的?”蝙蝠俠說:

          “這是給超人的。”



          你說:哦!我還以為是給神奇女俠的呢。

          蝙蝠俠說:不,這是給超人的,請在最后寫上 “I love you Superman.”。

          好的,我們來寫:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg" style="width:100%">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p>I love you Superman.</p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          這封信差不多完成了,蝙蝠俠另外想再做兩次改變。蝙蝠俠希望在最后段落的第一句中的 “does” 一詞是斜體,而 “I love you Superman” 這句話是粗體的。

          我們使用 <em> 和 <strong> 以斜體和粗體顯示文本。讓我們來更新這些更改:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg" style="width:100%">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>



          HTML 中的樣式

          你可以通過三種方式設置樣式或定義 HTML 元素的外觀:

          • 內聯樣式:我們使用元素的 style 屬性來編寫樣式。這是我們迄今為止使用的,但這不是一個好的實踐。
          • 嵌入式樣式:我們在由 <style> 和 </style> 包裹的 “style” 元素中編寫所有樣式。
          • 鏈接樣式表:我們在具有 .css 擴展名的單獨文件中編寫所有元素的樣式。此文件稱為樣式表。

          讓我們來看看如何定義 <div> 的內聯樣式:

          <div style="width:550px;">

          我們可以在 <style> 和 </style> 里面寫同樣的樣式:

          div{

          width:550px;

          }

          在嵌入式樣式中,我們編寫的樣式是與元素分開的。所以我們需要一種方法來關聯元素及其樣式。第一個單詞 “div” 就做了這樣的活。它讓瀏覽器知道花括號 {...} 里面的所有樣式都屬于 “div” 元素。由于這種語法確定要應用樣式的元素,因此它稱為一個選擇器。

          我們編寫樣式的方式保持不變:屬性(width)和值(550px)用冒號(:)分隔,以分號(;)結束。

          讓我們從 <div> 和 <img> 元素中刪除內聯樣式,將其寫入 <style> 元素:

          <style>

          div{

          width:550px;

          }

          img{

          width:100%;

          }

          </style>

          <div>

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          保存并刷新,結果應保持不變。

          但是有一個大問題,如果我們的 HTML 文件中有多個 <div> 和 <img> 元素該怎么辦?這樣我們在 <style> 元素中為 div 和 img 定義的樣式就會應用于頁面上的每個 div 和 img。

          如果你在以后的代碼中添加另一個 div,那么該 div 也將變為 550px 寬。我們并不希望這樣。

          我們想要將我們的樣式應用于現在正在使用的特定 div 和 img。為此,我們需要為 div 和 img 元素提供唯一的 id。以下是使用 id 屬性為元素賦予 id 的方法:

          <div id="letter-container">

          以下是如何在嵌入式樣式中將此 id 用作選擇器:

          #letter-container{

          ...

          }

          注意 # 符號。它表示它是一個 id,{...} 中的樣式應該只應用于具有該特定 id 的元素。

          讓我們來應用它:

          <style>

          #letter-container{

          width:550px;

          }

          #header-bat-logo{

          width:100%;

          }

          </style>

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          HTML 已經準備好了嵌入式樣式。

          但是,你可以看到,隨著我們包含越來越多的樣式,<style></style> 將變得很大。這可能很快會混亂我們的主 HTML 文件。

          因此,讓我們更進一步,通過將 <style> 標簽內的內容復制到一個新文件來使用鏈接樣式。

          在項目根目錄中創建一個新文件,將其另存為 “style.css”:

          #letter-container{

          width:550px;

          }

          #header-bat-logo{

          width:100%;

          }

          我們不需要在 CSS 文件中寫 <style> 和 </style>。

          我們需要使用 HTML 文件中的 <link> 標簽來將新創建的 CSS 文件鏈接到 HTML 文件。以下是我們如何做到這一點:

          <link rel="stylesheet" type="text/css" href="style.css">

          我們使用 <link> 元素在 HTML 文檔中包含外部資源,它主要用于鏈接樣式表。我們使用的三個屬性是:

          • rel:關系。鏈接文件與文檔的關系。具有 .css 擴展名的文件稱為樣式表,因此我們保留 rel=“stylesheet”。
          • type:鏈接文件的類型;對于一個 CSS 文件來說它是 “text/css”。
          • href:超文本參考。鏈接文件的位置。

          link 元素的結尾沒有 </link>。因此,<link> 也是一個自閉合的標簽。

          <link rel="gf" type="cute" href="girl.next.door">

          如果只是得到一個女朋友,那么很容易:D

          可惜沒有那么簡單,讓我們繼續前進。

          這是我們 “loveletter.html” 的內容:

          <link rel="stylesheet" type="text/css" href="style.css">

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          “style.css” 內容:

          #letter-container{

          width:550px;

          }

          #header-bat-logo{

          width:100%;

          }

          保存文件并刷新,瀏覽器中的輸出應保持不變。

          一些手續

          我們的情書已經準備好給蝙蝠俠,但還有一些正式的片段。

          與其他任何編程語言一樣,HTML 自出生以來(1990 年)經歷過許多版本,當前版本是 HTML5。

          那么,瀏覽器如何知道你使用哪個版本的 HTML 來編寫頁面呢?要告訴瀏覽器你正在使用 HTML5,你需要在頁面頂部包含 <!DOCTYPE html>。對于舊版本的 HTML,這行不同,但你不需要了解它們,因為我們不再使用它們了。

          此外,在之前的 HTML 版本中,我們曾經將整個文檔封裝在 <html></html> 標簽內。整個文件分為兩個主要部分:頭部在 <head></head> 里面,主體在 <body></body> 里面。這在 HTML5 中不是必須的,但由于兼容性原因,我們仍然這樣做。讓我們用 <Doctype>, <html>、 <head> 和 <body> 更新我們的代碼:

          <!DOCTYPE html>

          <html>

          <head>

          <link rel="stylesheet" type="text/css" href="style.css">

          </head>

          <body>

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          </body>

          </html>

          主要內容在 <body> 里面,元信息在 <head> 里面。所以我們把 <div> 保存在 <body> 里面并加載 <head> 里面的樣式表。

          保存并刷新,你的 HTML 頁面應顯示與之前相同的內容。

          HTML 的標題

          我發誓,這是最后一次改變。

          你可能已經注意到選項卡的標題正在顯示 HTML 文件的路徑:



          我們可以使用 <title> 標簽來定義 HTML 文件的標題。標題標簽也像鏈接標簽一樣在 <head> 內部。讓我們我們在標題中加上 “Bat Letter”:

          <!DOCTYPE html>

          <html>

          <head>

          <title>Bat Letter</title>

          <link rel="stylesheet" type="text/css" href="style.css">

          </head>

          <body>

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          </body>

          </html>

          保存并刷新,你將看到在選項卡上顯示的是 “Bat Letter” 而不是文件路徑。

          蝙蝠俠的情書現在已經完成。

          恭喜!你用 HTML 制作了蝙蝠俠的情書。



          我們學到了什么

          我們學習了以下新概念:

          • 一個 HTML 文檔的結構
          • 在 HTML 中如何寫元素(<p></p>)
          • 如何使用 style 屬性在元素內編寫樣式(這稱為內聯樣式,盡可能避免這種情況)
          • 如何在 <style>...</style> 中編寫元素的樣式(這稱為嵌入式樣式)
          • 在 HTML 中如何使用 <link> 在單獨的文件中編寫樣式并鏈接它(這稱為鏈接樣式表)
          • 什么是標簽名稱,屬性,開始標簽和結束標簽
          • 如何使用 id 屬性為一個元素賦予 id
          • CSS 中的標簽選擇器和 id 選擇器

          我們學習了以下 HTML 標簽:

          • <p>:用于段落
          • <br>:用于換行
          • <ul>、<li>:顯示列表
          • <div>:用于分組我們信件的元素
          • <h1>、<h2>:用于標題和子標題
          • <img>:用于插入圖像
          • <strong>、<em>:用于粗體和斜體文字樣式
          • <style>:用于嵌入式樣式
          • <link>:用于包含外部樣式表
          • <html>:用于包裹整個 HTML 文檔
          • <!DOCTYPE html>:讓瀏覽器知道我們正在使用 HTML5
          • <head>:包裹元信息,如 <link> 和 <title>
          • <body>:用于實際顯示的 HTML 頁面的主體
          • <title>:用于 HTML 頁面的標題

          我們學習了以下 CSS 屬性:

          • width:用于定義元素的寬度
          • CSS 單位:“px” 和 “%”

          朋友們,這就是今天的全部了,下一個教程中見。


          作者簡介:開發者 + 作者 | supersarkar.com | twitter.com/supersarkar


          via: https://medium.freecodecamp.org/for-your-first-html-code-lets-help-batman-write-a-love-letter-64c203b9360b

          作者: Kunal Sarkar 譯者: MjSeven 校對: wxy

          本文由 LCTT 原創編譯, Linux中國 榮譽推出

          點擊“了解更多”可訪問文內鏈接

          們今天來分析解釋一下這個表達式string hrefPattern = @"href\s*=\s*(?:""'[""']|(?<1>[^>\s]+))";,并用實例演示用法。這個正則表達式用于從文本中提取href屬性的值,這些值可以是被單引號或雙引號包圍的,或者是不包含大于符號和空白字符的文本。我們分解這個正則表達式來詳細解釋它的各個部分:

          1. href\s*=\s*: 這部分匹配 href 關鍵字,后面可以跟著零個或多個空白字符,然后是一個等號,再然后又是零個或多個空白字符。其中href: 直接匹配文本中的"href",這是HTML中表示鏈接地址的屬性名稱。\s*=\s*: 匹配等號(=),等號前后可以有0個或多個空白字符(包括空格、制表符、換行符等)。

          2. (?:...): 這是一個非捕獲組,意味著它會匹配括號內的內容,但不會為其創建一個捕獲組。這意味著我們不能直接從匹配結果中提取這部分內容。

          3. [""'](?<1>[^""']*)[""']: 這部分匹配被單引號或雙引號包圍的任何內容。具體來說:

          1. [""']: 匹配一個單引號或雙引號。

          2. (?<1>[^\"']*): 創建了一個命名捕獲組,名為1,用來捕獲在引號之間的任何非引號字符序列,這就是href屬性的值。(?<1>...): 這是一個命名捕獲組,但這里它被放在了一個非捕獲組內,這意味著它不會捕獲匹配的內容。

          3. [^""']*: 匹配任何不是單引號或雙引號的字符零次或多次。

          4. [""']: 再次匹配一個單引號或雙引號。

          4. |: 或者操作符,表示前面的模式和后面的模式中的任何一個可以匹配。又叫管道符號,代表邏輯“或”操作,也就是表示前面的模式與后面的模式任一滿足即可。

          5. (?<1>[^>\s]+): 這部分匹配任何不是大于符號或空白字符的字符一次或多次。這也是一個命名捕獲組,但同樣,它被放在了一個非捕獲組內。當href值沒有被引號包圍時使用。也就是這部分匹配不是大于符號(>)和空白字符的任何字符1次或多次,但不包括引號。

          綜上所述,此正則表達式能夠處理以下兩種格式的href屬性及其值:

          1. 被引號包圍的情況:<a href="http://example.com">...</a> 或 <a href='http://example.com'>...</a>

          2. 未被引號包圍的情況:<a href=http://example.com>...</a>

          實例演示用法:

          using System.Text.RegularExpressions;

          namespace ConsoleAppC

          {

          internal class Program

          {

          static void Main(string[] args)

          {

          string inputString = @"<a href=""http://example.com"">Link</a>

          <a href='http://another.example.com'>Another Link</a>

          <a href=http://noquotes.example.com>No Quotes Link</a>";

          string hrefPattern = @"href\s*=\s*(?:[""'](?<1>[^""']*)[""']|(?<1>[^>\s]+))";

          MatchCollection matches = Regex.Matches(inputString, hrefPattern);

          foreach (Match match in matches)

          {

          Console.WriteLine(match.Value); // 輸出匹配到的href屬性值

          Console.WriteLine($"Found href value: {match.Groups[1].Value} at index: {match.Groups[1].Index}");

          }

          }

          }

          }


          運行這段代碼后,將輸出如下結果:

          href="http://example.com"

          Found href value: http://example.com at index: 9

          href='http://another.example.com'

          Found href value: http://another.example.com at index: 72

          href=http://noquotes.example.com

          Found href value: http://noquotes.example.com at index: 150

          為了給大家演示如何使用這個正則表達式,我們再看以下例子:

          假設我們有以下的HTML片段:

          <a href="https://www.example.com">Click here</a>

          <a href='https://www.example.org'>Go there</a>

          <a href="https://www.example.net" target="_blank">Open external link</a>

          使用上述的正則表達式,我們可以提取所有的href屬性值:

          string input = @"<a href=\""https://www.example.com\"">Click here</a>

          <a href='https://www.example.org'>Go there</a>

          <a href=\""https://www.example.net\"" target=\""_blank\"">Open external link</a>";

          代碼為:

          string hrefPattern = @"href\s*=\s*(?:[""'](?<1>[^""']*)[""']|(?<1>[^>\s]+))";

          Regex regex = new Regex(hrefPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);

          MatchCollection matches = regex.Matches(input);

          foreach (Match match in matches)

          {

          Console.WriteLine($"Found href: {match.Groups["1"].Value}");

          }

          string input = @"<a href=\""https://www.example.com\"">Click here</a>

          輸出將是:

          Found href: \"https://www.example.com\"

          Found href: https://www.example.org

          Found href: \"https://www.example.net\"

          注意,這個正則表達式并不完美,它可能無法處理所有可能的HTML格式,但對于簡單的用途來說可能已經足夠了。


          主站蜘蛛池模板: 少妇一夜三次一区二区| 亚洲国产一区在线观看| 国产精品美女一区二区三区| 午夜视频久久久久一区| 色噜噜AV亚洲色一区二区| 99精品一区二区三区| 最新欧美精品一区二区三区| 在线观看日韩一区| chinese国产一区二区| 日韩精品成人一区二区三区| 国产91精品一区二区麻豆网站| 精品国产一区二区三区无码| 无码日韩人妻av一区免费| 成人国产精品一区二区网站| 国产午夜精品一区二区三区漫画 | 国产欧美一区二区精品仙草咪| 国产精品一区二区无线| 久久精品一区二区三区不卡| 中文字幕人妻AV一区二区| 爆乳熟妇一区二区三区霸乳| 久久一区二区明星换脸| 国产一区二区三区美女| 国产丝袜美女一区二区三区| 成人精品一区二区三区校园激情| 超清无码一区二区三区| 国产精品无码亚洲一区二区三区| 丰满人妻一区二区三区免费视频 | 精品国产一区二区三区AV | 亚洲熟妇av一区二区三区下载| 国产欧美一区二区精品仙草咪| 国产色情一区二区三区在线播放| 久久精品无码一区二区三区免费| 久久se精品一区二区影院| 日本无卡码一区二区三区| 三上悠亚一区二区观看| 国产av夜夜欢一区二区三区| 国产精品视频一区二区三区| 在线观看免费视频一区| 国产一区在线电影| 亚洲AV无码一区二区三区鸳鸯影院 | 久久精品国产一区二区三区肥胖|