如何为“选择”框建立占位符? - How do I make a placeholder for a 'select' box?

问题:

I'm using placeholders for text inputs which is working out just fine. 我正在使用占位符进行文本输入,效果很好。 But I'd like to use a placeholder for my selectboxes as well. 可是我也想为个人选择框使用一个占位符。 Of course I can just use this code: 固然,我能够使用如下代码: css

<select>
    <option value="">Select your option</option>
    <option value="hurr">Durr</option>
</select>

But the 'Select your option' is in black instead of lightgrey. 可是“选择您的选项”是黑色而不是浅灰色。 So my solution could possibly be CSS-based. 所以,个人解决方案可能基于CSS。 jQuery is fine too. jQuery也很好。 ide

This only makes the option grey in the dropdown (so after clicking the arrow): 这只会使下拉菜单中的选项变为灰色(所以,单击箭头后): this

option:first {
    color: #999;
}

The question is: How do people create placeholders in selectboxes? 问题是:人们如何在选择框中建立占位符? But it has already been answered, cheers. 但它已经获得回答,欢呼。 spa

And using this results in the selected value always being grey (even after selecting a real option): 使用此方法会致使所选值始终为灰色(即便在选择实选项后): .net

select {
    color: #999;
}

解决方案:

参考一: https://stackoom.com/question/OM9z/如何为-选择-框建立占位符
参考二: https://oldbug.net/q/OM9z/How-do-I-make-a-placeholder-for-a-select-box
相关文章
相关标签/搜索