简体   繁体   English

HTML:如何使标签在下拉菜单中可见?

[英]Html: How do i make label visible for drop-down?

How do I make my label visible? 如何使标签可见?

I have 2 drop-down and 2 labels. 我有2个下拉菜单和2个标签。

<label for="dropdown" class="answer">Model</label>

This is the label and other on same as this am trying to make it visible when drop-down is shown. 这是标签,与其他标签相同,这是在显示下拉列表时试图使其可见。

 $(".answer").hide(); 
 <base href="http://ice.com" /> <link rel="stylesheet" href="/gasss/css/ghd.css" type="text/css" media="all" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <fieldset> <form id="processContactUs" name="processContactUs" action="/send_form_email.php" method="POST"> <div> <label for="firstName">First name<span class="required">*</span></label> <input id="firstName" name="firstName" value="" type="text"> </div> <div> <label for="lastName">Surname<span class="required">*</span></label> <input id="lastName" name="lastName" value="" type="text"> </div> <div class="option"> <label for="gender">Model<span class="required">*</span></label> <div class="gender radio-pair"> <span> <input id="gender1" name="checkdrop" class="checkdrop" value="Ghd" onClick="ckChange(this)" type="checkbox"> <label for="gender1" onClick="ckChange(this)" >Ghd</label> </span> <span> <input id="gender2" name="checkdrop" class="checkdrop" value="Hair" onClick="ckChange(this)" type="checkbox"> <label for="gender2">Hair Dryer</label> </span> </div> </div> <div> <label for="email">Your email<span class="required">*</span></label> <input id="email" name="email" value="" type="email"> </div> <div class="answer"> <label for="dropdown" class="answer">Model</label> <select id="Ghd" name="dropdown" checked class="dropdown"> <option>Ghd Mk5.0</option> <option>Ghd Ms5.0</option> <option>Ghd SS5.0</option> <option>Ghd MK4.2B</option> <option>Ghd MS4.0</option> <option>Ghd SS4.0</option> <option>Ghd. Mk4.0</option> <option>Ghd. 3.1B</option> <option>Ghd 3</option> <option>Ghd SS</option> </select> </div> <div class="answer"> <label for="dropdown" class="answer">Model</label> <select id="Hair" name="dropdown" class="dropdown"> <option>toys</option> <option>games</option> <option>cartoons</option> </select> </div> <div class="opts"> <p>Please enter your ghd order number where possible</p> </div> <div class="textbox"> <label for="query"> Your query<span class="required">*</span> </label> <textarea id="query" name="query"></textarea> </div> <div class="opts"> </div> <div class="buttons"> <input name="contactUs" value="Submit" type="submit"> </div> </form> </fieldset> </div> <script type="text/javascript"> $('input[name=checkdrop]').click(function() { if (this.checked) { console.log(this.value); $('#' + this.value).parent().show(); } else { $('#' + this.value).parent().hide(); } }); </script> <script> function ckChange(ckType) { var ckName = document.getElementsByName(ckType.name); var checked = document.getElementById(ckType.id); if (checked.checked) { for (var i = 0; i < ckName.length; i++) { if (!ckName[i].checked) { ckName[i].disabled = true; } else { ckName[i].disabled = false; } } } else { for (var i = 0; i < ckName.length; i++) { ckName[i].disabled = false; } } } </script> <script type="text/javascript"> function valueChanged() { $(".answer").hide(); $(".checkdrop").click(function() { if ($(this).is(":checked")) { $(".answer").show(); } else { $(".answer").hide(); } }); }; $(".answer").hide(); </script> 

Hides the label and dropdown on form load so when checkbox are clicked the labels don't show, only the dropdown. 隐藏表单加载时的标签和下拉列表,以便在单击复选框时不显示标签,仅显示下拉列表。

You could either do this in CSS with the display attribute or you could do it straight from JQuery with .show() . 您可以在CSS中使用display属性来执行此操作,也可以直接在JQuery中使用.show() Here is an example of showing it after it has been hidden: $(".answer").show(); 这是一个隐藏后显示它的示例: $(".answer").show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM