问题:
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: 当然,我可以使用以下代码:
<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也很好。
This only makes the option grey in the dropdown (so after clicking the arrow): 这只会使下拉菜单中的选项变为灰色(因此,单击箭头后):
option:first {
color: #999;
}
The question is: How do people create placeholders in selectboxes? 问题是:人们如何在选择框中创建占位符? But it has already been answered, cheers. 但它已经得到回答,欢呼。
And using this results in the selected value always being grey (even after selecting a real option): 使用此方法会导致所选值始终为灰色(即使在选择实选项后):
select {
color: #999;
}
解决方案:
参考一: https://stackoom.com/question/OM9z/如何为-选择-框创建占位符参考二: https://oldbug.net/q/OM9z/How-do-I-make-a-placeholder-for-a-select-box
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4304471