[英]How should i show select title with css
Hello Guys Please Help me for this I didn't how I show select title.大家好,请帮帮我,我不知道如何显示选择的标题。 I want to show above When should we call you?.
我想在上面显示我们什么时候给你打电话?。
please check my code Thanks:-请检查我的代码谢谢:-
<select name="myfirst" title="When should we call you?">
<option class="optnoval"></option>
<option value="today" id="df">today</option>
<option value="tommorow" id="df">tommorow</option>
<option value="sunday" id="dfd">sunday</option>
</select>
Please check online codepen code link:- https://codepen.io/anon/pen/EQBbyG请查看在线 codepen 代码链接:- https://codepen.io/anon/pen/EQBbyG
You can add a <label>
in your HTML Markup.您可以在 HTML 标记中添加
<label>
。
<label for="myfirst">When should we call you?</label> <select name="myfirst" id="myfirst" title="When should we call you?"> <option class="optnoval"></option> <option value="today" id="df">today</option> <option value="tommorow" id="df">tommorow</option> <option value="sunday" id="dfd">sunday</option> </select>
If you use jQuery
you can select all the <select>
elements with a title
attribute, and copy its value into the first <option>
.如果您使用
jQuery
您可以选择所有带有title
属性的<select>
元素,并将其值复制到第一个<option>
。
$("select[title] option:first-child").text(function(i, oldtext) { if (oldtext.trim() == '') { return $(this).parent().attr("title"); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="myfirst" title="When should we call you?"> <option class="optnoval"></option> <option value="today">today</option> <option value="tommorow">tommorow</option> <option value="sunday" >sunday</option> </select> <select name="mytime" title="What time of day?"> <option class="optnoval"></option> <option value="morning">Morning</option> <option value="afternoon" >Afternoon</option> <option value="evening">Evening</option> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.