📜  HTML |<input type = "button">(1)

📅  最后修改于: 2023-12-03 15:15:38.866000             🧑  作者: Mango

HTML - <input type = "button">

The <input type = "button"> element is used in HTML to create a clickable button on a web page.

Syntax
<input type = "button" [attribute=value]>
Attributes
  • type: Specifies the type of button. In this case, it is set as "button". (Required)
  • value: Specifies the text that appears on the button. (Optional)
  • name: Defines the name of the button, which is used as the identifier when submitting a form. (Optional)
  • disabled: Disables the button so that it cannot be clicked. (Optional)
  • onclick: Specifies a JavaScript function to be executed when the button is clicked. (Optional)
  • class: Defines one or more CSS classes to be applied to the button. (Optional)
  • style: Specifies CSS styles to be applied to the button. (Optional)
  • id: Specifies a unique id for the button. (Optional)
Example Usage
<input type="button" value="Click Me!" onclick="myFunction()" class="button-style" id="myButton">

This example creates a button with the text "Click Me!" which, when clicked, will execute the JavaScript function myFunction(). The button has the CSS class "button-style" and has the unique id "myButton" assigned to it.

Notes
  • The <input type = "button"> element is a self-closing tag, meaning it does not have a closing tag.
  • If the value attribute is not specified, the default value for the button will be displayed, which is typically "Submit".

For more information, you can refer to the MDN web docs - <input> element.

Markdown类型代码片段:`````html

<input type="button" value="Click Me!" onclick="myFunction()" class="button-style" id="myButton">