How to create a <select> placeholder

假装没事ソ 提交于 2019-12-11 02:27:17

问题


In my select elements, I want a default text such as "please select an option". Also I use the jQuery plugin Validation with my form so that the user cannot submit the form if he has not selected something in my select elements.

Problem is, if I have "please select an option" in my selects, the form will validate.

How to deal with this problem?


回答1:


<select>
    <option value="">Please select an option</option>

<option> content is only used when the value is not empty.

http://jsfiddle.net/s5AVg/




回答2:


<select>
    <option style="display:none">please select an option</option>
    <option disabled="disabled">I am a line</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>


来源:https://stackoverflow.com/questions/16222655/how-to-create-a-select-placeholder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!