<label id="ddx7a"></label>

    <span id="ddx7a"></span>
      <rt id="ddx7a"></rt><rt id="ddx7a"></rt>
      \n
      \nSelect your favorite color:\n\n<\/form>\n<\/body><\/pre>\n

      上面的 HTML 代碼包含一個(gè)使用名為“color”的輸入類型的 FORM 元素。此顏色輸入類型創(chuàng)建并顯示最簡(jiǎn)單的顏色選擇器,即 Windows 標(biāo)準(zhǔn)顏色選擇器。它允許用戶選擇自己喜歡的顏色。<\/p>\n

      作為顏色的輸入類型創(chuàng)建一個(gè)文本框或多個(gè)按鈕,其默認(rèn)背景顏色為“黑色”。當(dāng)我們點(diǎn)擊它時(shí),它會(huì)為用戶顯示顏色選擇。<\/p>\n

      觀察下面給出的顏色選擇器的工作原理:<\/p>\n

      第 1 步:<\/strong> 單擊默認(rèn)背景色為“黑色”的按鈕。<\/p>\n

      \"HTML<\/p>\n

      上面的代碼只是創(chuàng)建了一個(gè)如上所示的按鈕。<\/p>\n

      第 2 步:<\/strong> 單擊并選擇您的新顏色。<\/p>\n

      \"HTML<\/p>\n

      \"HTML<\/p>\n

      第3步<\/strong>:我們選擇了明亮的綠色進(jìn)行演示。單擊“確定<\/strong>”按鈕。<\/p>\n

      \"HTML<\/p>\n

      In the above screen-shots, you can easily see the selected color is shown in the last screen-shot.<\/p>\n

      The input type ‘color’ provides this simple functionality of a color picker in HTML5. After picking your color, it is your choice of what the selected color can be used for.<\/p>\n

      In the following example,?<\/strong>I incremented the above example and modified it with some inclusions.<\/p>\n

      The following example is a combination of HTML and Javascript. This example has a FORM element that uses the input type ‘color’ tag. This FORM, when submitted, our JAVASCRIPT is triggered.<\/p>\n

      Observe the source code for the FORM element below:<\/p>\n\n\n

      Code:<\/strong><\/p>\n

      
      

      国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

      \n\nSelect your favorite color:\n\n\n<\/form>\n<\/body><\/pre>\n

      We added a new line to our previous program. A submit button. This submit button is when clicked; our Java script is triggered, which is given below:<\/p>\n

      function ReturnColor(c)\n{\n\/\/saving the selected color value by ID\nvar c= document.getElementById(\"color\").value;\nvar str= new String (\"You chose:\");\n\/\/The color is saved as its HEX color code.\ndocument.write(str+c);\n}<\/pre>\n

      When the ‘Submit’ button is clicked, our function in javascript is triggered. The above function, ReturnColor (), returns the HEX code, that is,<\/strong> Hexadecimal code for the selected color by our color picker. When the code is executed, the following is our output.<\/p>\n

      \"HTML<\/p>\n

      \"HTML<\/p>\n

      The above output is in the HEX code. The 6 numbers represent the inclusion of Red, Green and Blue colors resulting in the selected color. This HEX code can also be converted easily into RGB code.<\/p>\n

      Similarly, we can save the above code and set it as a background color or a font color for the user. To do so, we added a few more lines of code into our already existing source code.<\/p>\n

      Following is the complete code, with the HTML body remaining the same:<\/p>\n

      	
      
      
      
      
      
      
      	
      
      目錄
      HTML 顏色選擇器
      創(chuàng)建顏色選擇器的源代碼
      Conclusion
      首頁(yè) web前端 html教程 HTML 顏色選擇器

      HTML 顏色選擇器

      Sep 04, 2024 pm 04:35 PM
      html html5 HTML Tutorial HTML Properties HTML tags

      眾所周知,HTML被稱為超文本標(biāo)記語(yǔ)言,它用于在瀏覽器上顯示文本,并借助其特殊的輔助腳本(例如JavaScript和CSS),使您的內(nèi)容變得美觀。顏色編碼是美化 HTML 網(wǎng)頁(yè)的一部分。

      HTML 中的顏色代碼充當(dāng)標(biāo)識(shí)符,用于在網(wǎng)絡(luò)上標(biāo)識(shí)和表示該顏色。常用的顏色編碼是十六進(jìn)制,表示該顏色的“十六進(jìn)制”代碼。同樣,還有其他顏色代碼,例如 RGB,“紅、綠、藍(lán)”的縮寫(xiě)。另一種顏色代碼稱為 HSL,是“色調(diào)、飽和度、亮度”的縮寫(xiě)。在選擇您喜歡的顏色時(shí),HSL 是一個(gè)額外的優(yōu)勢(shì)。

      由于一般情況下優(yōu)先使用十六進(jìn)制代碼,因此我們已經(jīng)盡力解釋了十六進(jìn)制代碼。十六進(jìn)制顏色代碼包含一個(gè)符號(hào)、一個(gè)哈希值 (#) 和一組六位數(shù)字或數(shù)字。它們采用十六進(jìn)制數(shù)字系統(tǒng),因此“FF”是最高數(shù)字,代表十六進(jìn)制數(shù)字系統(tǒng)中的255”。

      這六位數(shù)字包含三對(duì)代表 RB 顏色代碼。在這六位數(shù)字中,第一對(duì)兩位數(shù)字代表“紅色”顏色的強(qiáng)度。因此,第一對(duì)位置的“FF”將代表最大強(qiáng)度的紅色。 “00”用于最低強(qiáng)度,“FF”用于最高強(qiáng)度。為了獲得“綠色”顏色,中間的一對(duì)代表強(qiáng)度。

      同樣,對(duì)于“藍(lán)色”,最后一對(duì)代表強(qiáng)度。

      • 因此,諸如 #FF0000 之類的十六進(jìn)制數(shù)字將導(dǎo)致??HTML 顏色選擇器
      • 十六進(jìn)制數(shù)字,例如 #00FF00 將導(dǎo)致? ??HTML 顏色選擇器
      • 十六進(jìn)制數(shù)字,例如 #0000FF 將導(dǎo)致??HTML 顏色選擇器
      • 要獲得黃色(“紅色”和“綠色”的組合),會(huì)創(chuàng)建一個(gè)類似的十六進(jìn)制數(shù)字,例如#FFFF00。

      HTML 顏色選擇器

      顏色選擇器創(chuàng)建后,允許用戶挑選”自己選擇的顏色。最標(biāo)準(zhǔn)的顏色選擇器用于 Windows 應(yīng)用程序,例如 MS Word 或 Paint 等。大家都熟悉顏色選擇器;你可以通過(guò)看下面的圖片來(lái)喚起你的記憶:

      HTML 顏色選擇器

      輸入類型“color用于創(chuàng)建包含顏色的輸入字段。但某些瀏覽器(例如 Internet Explorer 11 及更早版本)不支持此輸入類型。因此,根據(jù)瀏覽器的不同,當(dāng)您使用輸入類型時(shí)會(huì)彈出一個(gè)顏色選擇器。有些瀏覽器會(huì)簡(jiǎn)單地將此輸入字段轉(zhuǎn)換為文本框,如下所示:

      HTML 顏色選擇器

      因此,當(dāng)使用支持的瀏覽器時(shí),相同的代碼將產(chǎn)生以下顏色選擇器調(diào)色板。

      HTML 顏色選擇器

      單擊該彩色框時(shí),會(huì)彈出一個(gè)調(diào)色板。這里我使用的是 Google Chrome 版本‘78.0.3904.97’,它支持輸入類型顏色屬性。

      HTML 顏色選擇器

      創(chuàng)建此類顏色選擇器的代碼將在下一節(jié)中解釋。

      創(chuàng)建顏色選擇器的源代碼

      以下是在 HTML 中創(chuàng)建最簡(jiǎn)單的顏色選擇器的說(shuō)明。請(qǐng)參閱以下代碼:

      代碼

      <body>
      <form action="HTMLColorPicker.html">
      Select your favorite color:
      <input type="color" name="favcolor" id="color" >
      </form>
      </body>

      上面的 HTML 代碼包含一個(gè)使用名為“color”的輸入類型的 FORM 元素。此顏色輸入類型創(chuàng)建并顯示最簡(jiǎn)單的顏色選擇器,即 Windows 標(biāo)準(zhǔn)顏色選擇器。它允許用戶選擇自己喜歡的顏色。

      作為顏色的輸入類型創(chuàng)建一個(gè)文本框或多個(gè)按鈕,其默認(rèn)背景顏色為“黑色”。當(dāng)我們點(diǎn)擊它時(shí),它會(huì)為用戶顯示顏色選擇。

      觀察下面給出的顏色選擇器的工作原理:

      第 1 步: 單擊默認(rèn)背景色為“黑色”的按鈕。

      HTML 顏色選擇器

      上面的代碼只是創(chuàng)建了一個(gè)如上所示的按鈕。

      第 2 步: 單擊并選擇您的新顏色。

      HTML 顏色選擇器

      HTML 顏色選擇器

      第3步:我們選擇了明亮的綠色進(jìn)行演示。單擊“確定”按鈕。

      HTML 顏色選擇器

      In the above screen-shots, you can easily see the selected color is shown in the last screen-shot.

      The input type ‘color’ provides this simple functionality of a color picker in HTML5. After picking your color, it is your choice of what the selected color can be used for.

      In the following example,?I incremented the above example and modified it with some inclusions.

      The following example is a combination of HTML and Javascript. This example has a FORM element that uses the input type ‘color’ tag. This FORM, when submitted, our JAVASCRIPT is triggered.

      Observe the source code for the FORM element below:

      Code:

      <body>
      <form action="HTMLColorPicker.html">
      Select your favorite color:
      <input type="color" name="favcolor" id="color" >
      <input type="submit" onclick = "ReturnColor()" id="submit" />
      </form>
      </body>

      We added a new line to our previous program. A submit button. This submit button is when clicked; our Java script is triggered, which is given below:

      function ReturnColor(c)
      {
      //saving the selected color value by ID
      var c= document.getElementById("color").value;
      var str= new String ("You chose:");
      //The color is saved as its HEX color code.
      document.write(str+c);
      }

      When the ‘Submit’ button is clicked, our function in javascript is triggered. The above function, ReturnColor (), returns the HEX code, that is, Hexadecimal code for the selected color by our color picker. When the code is executed, the following is our output.

      HTML 顏色選擇器

      HTML 顏色選擇器

      The above output is in the HEX code. The 6 numbers represent the inclusion of Red, Green and Blue colors resulting in the selected color. This HEX code can also be converted easily into RGB code.

      Similarly, we can save the above code and set it as a background color or a font color for the user. To do so, we added a few more lines of code into our already existing source code.

      Following is the complete code, with the HTML body remaining the same:

      <script>
      function ReturnColor(c)
      {
      //saving the selected color value by ID
      var c= document.getElementById("color").value;
      var str= new String ("You chose:");
      //The color is saved as its HEX color code
      document.write(str+c);
      document.write("<br/>");
      //A HEX color code can be converted into RGB code
      var R=c.slice(1,3);
      var G=c.slice(3,5);
      var B=c.slice(5);
      //Displaying the corresponding RGB code
      document.write("In RGB format, RGB("
      + parseInt(R,16) + ","
      + parseInt(G,16) + ","
      + parseInt(B,16) + ")");
      document.write("<br/>");
      //Setting our selected color as Font color
      var color = c;
      var str1 = "Your color will appear as this font color";
      var str2 = str1.fontcolor(c);
      document.write(str2);
      //Setting our selected color as Background color
      document.write("<div style='border: solid; height: 90px; width: 90px; background-color:"+color+"'/>");
      }
      </script>

      This is our complete script. When the code is executed, and a color is selected, the following is the output that is displayed.

      HTML 顏色選擇器

      Conclusion

      There are many ways and many combinations that can help you to create a color picker, that too smart one. For example, with the combination of HTML5 and CSS and JavaScript, you can use yet another element called ‘canvas’ that has its own libraries that helps create a lightweight, small and cross-browser color picker. But that’s for another time.

      以上是HTML 顏色選擇器的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

      本站聲明
      本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

      熱AI工具

      Undress AI Tool

      Undress AI Tool

      免費(fèi)脫衣服圖片

      Undresser.AI Undress

      Undresser.AI Undress

      人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

      AI Clothes Remover

      AI Clothes Remover

      用于從照片中去除衣服的在線人工智能工具。

      Clothoff.io

      Clothoff.io

      AI脫衣機(jī)

      Video Face Swap

      Video Face Swap

      使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

      熱工具

      記事本++7.3.1

      記事本++7.3.1

      好用且免費(fèi)的代碼編輯器

      SublimeText3漢化版

      SublimeText3漢化版

      中文版,非常好用

      禪工作室 13.0.1

      禪工作室 13.0.1

      功能強(qiáng)大的PHP集成開(kāi)發(fā)環(huán)境

      Dreamweaver CS6

      Dreamweaver CS6

      視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

      SublimeText3 Mac版

      SublimeText3 Mac版

      神級(jí)代碼編輯軟件(SublimeText3)

      熱門(mén)話題

      Laravel 教程
      1597
      29
      PHP教程
      1488
      72
      初學(xué)者的基本HTML標(biāo)簽 初學(xué)者的基本HTML標(biāo)簽 Jul 27, 2025 am 03:45 AM

      要快速入門(mén)HTML,只需掌握幾個(gè)基礎(chǔ)標(biāo)簽即可搭建網(wǎng)頁(yè)骨架。1.頁(yè)面結(jié)構(gòu)必備、和,其中是根元素,包含元信息,是內(nèi)容展示區(qū)域。2.標(biāo)題使用到,級(jí)別越高數(shù)字越小,正文用標(biāo)簽分段,避免跳級(jí)使用。3.鏈接使用標(biāo)簽并配合href屬性,圖片使用標(biāo)簽并包含src和alt屬性。4.列表分為無(wú)序列表和有序列表,每個(gè)條目用表示且必須嵌套在列表中。5.初學(xué)者不必強(qiáng)記所有標(biāo)簽,邊寫(xiě)邊查更高效,掌握結(jié)構(gòu)、文本、鏈接、圖片和列表即可制作基礎(chǔ)網(wǎng)頁(yè)。

      影子dom概念和HTML集成 影子dom概念和HTML集成 Jul 24, 2025 am 01:39 AM

      ShadowDOM是Web組件技術(shù)中用于創(chuàng)建隔離DOM子樹(shù)的技術(shù)。1.它允許在普通HTML元素上掛載獨(dú)立的DOM結(jié)構(gòu),擁有自己的樣式和行為,不與主文檔互相影響;2.通過(guò)JavaScript創(chuàng)建,例如使用attachShadow方法并設(shè)置mode為open;3.結(jié)合HTML使用時(shí)具備結(jié)構(gòu)清晰、樣式隔離和內(nèi)容投影(slot)三大特點(diǎn);4.注意事項(xiàng)包括調(diào)試復(fù)雜、樣式作用域控制、性能開(kāi)銷及框架兼容性問(wèn)題??傊?,ShadowDOM提供了原生封裝能力,適用于構(gòu)建可復(fù)用且不污染全局的UI組件。

      html'樣式”標(biāo)簽:內(nèi)聯(lián)與內(nèi)部CSS html'樣式”標(biāo)簽:內(nèi)聯(lián)與內(nèi)部CSS Jul 26, 2025 am 07:23 AM

      樣式放置方式需根據(jù)場(chǎng)景選擇。1.Inline適合單元素臨時(shí)修改或JS動(dòng)態(tài)控制,如按鈕顏色隨操作變化;2.內(nèi)部CSS適合頁(yè)面少、結(jié)構(gòu)簡(jiǎn)單項(xiàng)目,便于集中管理樣式,如登錄頁(yè)基礎(chǔ)樣式設(shè)置;3.優(yōu)先考慮復(fù)用性、維護(hù)性及性能,大項(xiàng)目拆分外鏈CSS文件更優(yōu)。

      為什么我的圖像未顯示在HTML中? 為什么我的圖像未顯示在HTML中? Jul 28, 2025 am 02:08 AM

      圖像未顯示通常因文件路徑錯(cuò)誤、文件名或擴(kuò)展名不正確、HTML語(yǔ)法問(wèn)題或?yàn)g覽器緩存導(dǎo)致。1.確保src路徑與文件實(shí)際位置一致,使用正確的相對(duì)路徑;2.檢查文件名大小寫(xiě)及擴(kuò)展名是否完全匹配,并通過(guò)直接輸入U(xiǎn)RL驗(yàn)證圖片能否加載;3.核對(duì)img標(biāo)簽語(yǔ)法是否正確,確保無(wú)多余字符且alt屬性值恰當(dāng);4.嘗試強(qiáng)制刷新頁(yè)面、清除緩存或使用隱身模式排除緩存干擾。按此順序排查可解決大多數(shù)HTML圖片顯示問(wèn)題。

      您可以在另一個(gè)標(biāo)簽中放置一個(gè)標(biāo)簽嗎? 您可以在另一個(gè)標(biāo)簽中放置一個(gè)標(biāo)簽嗎? Jul 27, 2025 am 04:15 AM

      ?Youcannotnesttagsinsideanothertagbecauseit’sinvalidHTML;browsersautomaticallyclosethefirstbeforeopeningthenext,resultinginseparateparagraphs.?Instead,useinlineelementslike,,orforstylingwithinaparagraph,orblockcontainerslikeortogroupmultipleparagraph

      html'鏈接”預(yù)取DNS html'鏈接”預(yù)取DNS Jul 23, 2025 am 02:19 AM

      提前解析DNS能加快頁(yè)面加載速度,使用HTML的link標(biāo)簽進(jìn)行DNS預(yù)解析是有效方法;DNSPrefetching是通過(guò)提前解析域名,節(jié)省后續(xù)請(qǐng)求時(shí)間;適用場(chǎng)景包括第三方字體、廣告統(tǒng)計(jì)腳本、資源托管和CDN域名;建議優(yōu)先處理主頁(yè)面依賴資源,合理控制數(shù)量在3~5個(gè),并搭配preconnect使用效果更佳。

      如何編寫(xiě)基本的HTML5頁(yè)模板? 如何編寫(xiě)基本的HTML5頁(yè)模板? Jul 26, 2025 am 07:23 AM

      聲明文檔為HTML5,避免瀏覽器進(jìn)入怪異模式;2.定義根元素并指定語(yǔ)言以提升可訪問(wèn)性和SEO;3.中包含確保正確字符編碼,實(shí)現(xiàn)響應(yīng)式設(shè)計(jì),設(shè)置頁(yè)面標(biāo)題;4.放置所有可見(jiàn)內(nèi)容,可選添加CSS、favicon和JavaScript鏈接;該模板結(jié)構(gòu)完整、兼容現(xiàn)代瀏覽器,適用于任何新HTML文件。

      輸入標(biāo)簽中的名稱屬性是什么? 輸入標(biāo)簽中的名稱屬性是什么? Jul 27, 2025 am 04:14 AM

      thenAmeatTributeInAninputTagisusIfe to IndentifyTheInputWhentheFormisSubSted; iservesAsTheKeyInthekey-ValuePairsentTotheserver,wheretheuser'sinputisthevalue.1.whenaformented,

      See all articles