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

前端 未结 13 2413
不知归路
不知归路 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:42

    Works perfectly fine if the first option's value is null. Explanation : The HTML5 will read a null value on button submit. If not null (value attribute), the selected value is assumed not to be null hence the validation would have worked i.e by checking if there's been data in the option tag. Therefore it will not produce the validation method. However, i guess the other side becomes clear, if the value attribute is set to null ie (value = "" ), HTML5 will detect an empty value on the first or rather the default selected option thus giving out the validation message. Thanks for asking. Happy to help. Glad to know if i did.

提交回复
热议问题