Can I apply the required attribute to <select> fields in HTML5?

前端 未结 13 2390
不知归路
不知归路 2020-11-22 16:20

How can I check if a user has selected something from a doesn\'t support the new

13条回答
  •  日久生厌
    2020-11-22 16:40

    You need to set the value attribute of option to the empty string:

    
    

    select will return the value of the selected option to the server when the user presses submit on the form. An empty value is the same as an empty text input -> raising the required message.


    w3schools

    The value attribute specifies the value to be sent to a server when a form is submitted.

    Example

提交回复
热议问题