Friday, February 26, 2021

Button

 Кнопки активно используются в страничках, веб приложениях. Вот пара нюансов:

  1. Кнопки за пределами формы по умолчанию ничего не делают. Нужно делать обработку кликов с помощью javascript.
  2. Кнопки в пределах формы имеют один из трех типов:
    1. submit - отправка формы
    2. reset - очистка формы
    3. button - ничего не делает по умолчанию
  3. Тип задается через атрибут type. Если не задать или задать неправильное значение - тип будет submit.

type
The default behavior of the button. Possible values are:
  • submit: The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form>, or if the attribute is an empty or invalid value.
  • reset: The button resets all the controls to their initial values, like <input type="reset">. (This behavior tends to annoy users.)
  • button: The button has no default behavior, and does nothing when pressed by default. It can have client-side scripts listen to the element's events, which are triggered when the events occur.



Внутри формы, следующие варианты будут работать одинаково:


<button type="submit">OK</button>
<button>OK</button>

No comments: