搜尋
首頁web前端html教學HTML 按鈕標籤

HTML 按鈕標籤

Sep 04, 2024 pm 04:29 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

HTML 按鈕標籤允許使用 HTML 文件在網頁上建立活動按鈕控制項。這個元素在 body 標籤內宣告。為什麼我們需要一個按鈕元素?通常,當使用者造訪網頁時,他最常見的行為是點擊網站上的某個位置,從而轉到下一個 URL 頁面。為此,Button 元素無法單獨完成;它是由表單操作創建的,其中 Web 表單有一個預設的提交按鈕可以點擊。

按鈕是使用

文法:

與其他 HTML 標籤一樣,即使按鈕標籤也有開始和結束標籤,且按鈕類型是使用屬性定義的。

<button>
// some stuff like content / image
</button>

HTML 按鈕標籤的屬性

沒有使用特殊屬性,因為它們沒有任何必需的屬性;相反,它們被用作具有type=” 屬性的普通按鈕。“甚至這個元素也是使用CSS 設計的,其屬性可以改變按鈕標籤中的變化。這些屬性是 CSS 字體系列、字體粗細、文字裝飾和字體樣式。背景顏色等著色屬性和文字溢出和文字縮排等佈局屬性。

S.no Attribute Name Description Example
1 autofocus  It is considered a Boolean attribute.
2 disabled Making a button non-clickable.
3 Form It Creates a form
4 formaction It specifies the current location for submitting the form data.
5 formnovalidate  It appears in gray and gives non-validation features.
6 Formmethod It specifies the methods while referring to the next web  page(get the post of HTTP methods)
7 formtarget  It specifies the target path for the server response when a form action is done.
8 formenctype It has been used when a form is submitted to the webserver for the response; it activates the type of content used.
8 name  It specifies the button name used in the form element, which is used by form inputs.
9 type  It specifies the type of button being used. It has three default values submit, reset, and text.
10 value It gives an initial value when a button is used along with the form data
11 tabindex It specifies the tab key and the order does the preference.
12 onclick When a button is pressed, it runs a small javascript code behind it.

Examples to Implement in HTML Button Tag

Below are examples of implementing an HTML Button Tag:

Example #1

Code:



<title> HTML button tag Example</title>


<h2 id="HTML-button-tag-Example">HTML button tag Example </h2>

Employee Name:

Output:

HTML 按鈕標籤

Example #2

Code:



<h3> <center> Example using CSS </center>
<h3>


Normal Class
<button type="button">Add to the First class</button>
<hr>
Economic Class
<button type="button" style="color: pink;"><b> Book Economic Class </b></button>
<hr>
Bussiness class
<button type="button" style="color: orange;"><b> Book Bussiness  Class </b></button>
<hr>
Departure
<button type="button" style="font: bold 12px Open Sans;">Norway </button><br>

</h3>
</h3>

Output:

HTML 按鈕標籤

Example #3

With CSS: Here, we have used padding and margin property. Here are some ways to look at the page better. To create a button with rounded corners, use border-radius.

Code:

<style>
body {
color: #000;
height: 90vh;
background: linear-gradient(-90deg, #a1c3d1 0%, #c48b9e 100%) no-repeat;
text-align: center;
}
input {
width: 280px;
display: block;
margin: 2rem auto;
border: 3px solid #fbc7ff;
padding: 7px;
background: transparent;
border-radius: 25px;
outline: none;
}
::placeholder {
color: #00ced1;
}
.btn {
background:#96f905;
border: none;
height: 3rem;
border-radius: 20px;
width: 220px;
display: block;
color: #96f905;
outline: none;
margin: 2rem auto;
}
</style>

<h1 id="HTML-Form-action-Using-Button">HTML Form action Using Button</h1>

Output:

HTML 按鈕標籤

Note: You can also increase the button size by giving . btn in the above code is the bootstrap function class.

Example #4

The below example shows how to use the attribute autofocus with button element; in an example, when a page Loads, it focuses on the first HTML control.

Code:



<title>
Button Demo
<button>autofocus Attribute
</button>
</title>


<h1 style="color: blue;">
EDUCBA Web Tutorial
</h1>
<h2> Button Tag
<button>autofocus Attribute
</button>
</h2>
<h2> Button Tag
<button>autofocus Attribute
</button>
</h2>
<button id="GFG" autofocus>
Press
</button>
<br>

Output:

HTML 按鈕標籤

Example #5

onclick attribute demo. In the below example, I have used JavaScript to take action in the button; meanwhile, it alerts a dialog box with a text message. We use a JavaScript function to make the critical decision by activating the button with onclick().

Code:



<title>HTML  On Click Button Demo</title>


<h3 id="HTML-On-Click-Button-Demo"> HTML  On Click Button Demo</h3>
<button onclick="alert('Hi Welcome to EDUCBA!')"> Press me... </button>

Output: Before the button press

HTML 按鈕標籤

Alert Message – After the Button click

HTML 按鈕標籤

Example #6

Code:



<script type="text/javascript" src="scripts.js">
</script>
<link rel="stylesheet" href="styles.css">
<script type="text/javascript" src="scripts.js"></script>
<link rel="stylesheet" href="styles.css">


<p>The button loads to the next web page!</p>
<a href="https://www.educba.com" target="_blank">
<button>Submit!</button>
</a>

Output:

HTML 按鈕標籤

Conclusion  

In summary, we have learned about the HTML Button tag. This tag initiates an action and submits content within an HTML document. Important aspects of the website create an easy button, CSS, and JavaScript to look colorful. You can also learn many options related to buttons.

以上是HTML 按鈕標籤的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
HTML行動:網站結構的示例HTML行動:網站結構的示例May 05, 2025 am 12:03 AM

HTML用於構建結構清晰的網站。 1)使用標籤如、、定義網站結構。 2)示例展示了博客和電商網站的結構。 3)避免常見錯誤如標籤嵌套不正確。 4)優化性能通過減少HTTP請求和使用語義化標籤。

您如何將圖像插入HTML頁面?您如何將圖像插入HTML頁面?May 04, 2025 am 12:02 AM

toinsertanimageIntoanhtmlpage,usethetagwithsrcandaltattributes.1)usealttextforAcccessibilityandseo.2)instementRcsetForresponSiveImages.3)applylazyloadingWithLoadingWithLoading =“ lazy” tooptimizeperformance.4)tooptimizeperformance.4)

HTML的目的:啟用Web瀏覽器可以顯示內容HTML的目的:啟用Web瀏覽器可以顯示內容May 03, 2025 am 12:03 AM

HTML的核心目的在於讓瀏覽器理解並展示網頁內容。 1.HTML通過標籤定義網頁結構和內容,如、到、等。 2.HTML5增強了多媒體支持,引入了和標籤。 3.HTML提供了表單元素,支持用戶交互。 4.優化HTML代碼可提升網頁性能,如減少HTTP請求和壓縮HTML。

為什麼HTML標籤對Web開發很重要?為什麼HTML標籤對Web開發很重要?May 02, 2025 am 12:03 AM

htmltagsareessentialforwebdevelopmentastheyandendenhancewebpages.1)semantictagsimproveaccessibilityandseo.2)semanteLayOut,語義和互動性。 3)poseriblesibilityandseoandseo.3)poseriblesoftagscanoftagscanoftagscanoptagscanoptimizeperefeneandimizeanDenSuroceRecRoscRoss-BrowserCrowserCercerComercompatibility。

說明將一致的編碼樣式用於HTML標籤和屬性的重要性。說明將一致的編碼樣式用於HTML標籤和屬性的重要性。May 01, 2025 am 12:01 AM

一致的HTML編碼風格很重要,因為它提高了代碼的可讀性、可維護性和效率。 1)使用小寫標籤和屬性,2)保持一致的縮進,3)選擇並堅持使用單引號或雙引號,4)避免在項目中混合使用不同風格,5)利用自動化工具如Prettier或ESLint來確保風格的一致性。

如何在 Bootstrap 4 中實現多項目輪播?如何在 Bootstrap 4 中實現多項目輪播?Apr 30, 2025 pm 03:24 PM

在Bootstrap4中實現多項目輪播的解決方案在Bootstrap4中實現多項目輪播並不是一件簡單的事情。雖然Bootstrap...

deepseek官網是如何實現鼠標滾動事件穿透效果的?deepseek官網是如何實現鼠標滾動事件穿透效果的?Apr 30, 2025 pm 03:21 PM

如何實現鼠標滾動事件穿透效果?在我們瀏覽網頁時,經常會遇到一些特別的交互設計。比如在deepseek官網上,�...

HTML 視頻的播放控件樣式怎麼修改HTML 視頻的播放控件樣式怎麼修改Apr 30, 2025 pm 03:18 PM

無法直接通過CSS修改HTML視頻的默認播放控件樣式。 1.使用JavaScript創建自定義控件。 2.通過CSS美化這些控件。 3.考慮兼容性、用戶體驗和性能,使用庫如Video.js或Plyr可簡化過程。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),