我有以下 HTML 标记:-
<select name="Fault" class="textbox" id="fault">
<option>Single Light Out</option>
<option>Light Dim</option>
<option>Light On In Daytime</option>
<option>Erratic Operating Times</option>
<option>Flashing/Flickering</option>
<option>Causing Tv/Radio Interference</option>
<option>Obscured By Hedge/Tree Branches</option>
<option>Bracket Arm Needs Realigning</option>
<option>Shade/Cover Missing</option>
<option>Column In Poor Condition</option>
<option>Several Lights Out (please state how many)</option>
<option>Column Leaning</option>
<option>Door Missing/Wires Exposed</option>
<option>Column Knocked Down/Traffic Accident</option>
<option>Lantern Or Bracket Broken Off/Hanging On Wires</option>
<option>Shade/Cover Hanging Open</option>
</select>
<span id="faulttext" style="color:Red; display:none">Text in the span</span>
此 Jquery 片段将最后 5 个选项添加到选项组中。
$('#fault option:nth-child(n+12)').wrapAll('<optgroup label="Urgent Reasons">');
我想要做的是,display:none
如果选择了其中的任何项目,则删除<optgroup>
,有效地显示跨度消息,可能带有淡入淡出的过渡,如果选择了之外的任何选项,也隐藏消息<optgroup>
。