【发布时间】:2012-03-05 19:58:37
【问题描述】:
在我的表单(如下所示)上,我有一组单选选项。如果用户选择“其他”的最后一个选项,我希望 div 显示并向下滑动,他们可以在文本框中输入自定义值。我还希望能够以相同的形式多次拥有同一进程的多个实例(显然具有不同的 ID)。
这是它的设置方式:如果用户选择了类为“color_toggle”且值等于“Other”的单选按钮,我希望它显示元素 ID“specify_color_box”。如果他们选择不同的单选按钮,我希望隐藏相同的元素。
这是答案,以防万一其他人有同样的问题。 我的表单元素显示在这里:
<fieldset class="w100">
<div class="rowElem align-left">
<input type="radio" id="Gray" name="color" value="Gray" class="color_toggle" checked >
<label>Gray (Standard)</label>
</div>
<div class="rowElem align-left">
<input type="radio" id="All Yellow" name="color" value="All Yellow" class="color_toggle">
<label>All Yellow</label>
</div>
<div class="rowElem align-left">
<input type="radio" id="Yellow Posts Black Panels" name="color" value="Yellow Posts Black Panels" class="color_toggle">
<label>Yellow Posts / Black Panels</label>
</div>
<div class="rowElem align-left">
<input type="radio" id="other_color" name="color" value="Other" class="color_toggle">
<label>Other</label>
</div>
<div id="specify_color_box" class="form-subscr-field rowElem align-left" style="display:none;">
<label for="specify_color" id="specify_color_label">Specify Custom Color: </label>
<input id="specify_color" type="text" name="specify_color" class="inputbox" size="10" value="Enter custom color" onFocus="if(this.value=='Enter custom color') this.value='';" onBlur="if(this.value=='') this.value='Enter custom color';"/>
</div>
</fieldset>
我的 jQuery 显示在这里:
$(document).ready(function(){
$("input[name='color']").click(function(){
if($(this).val() == "Other") {
$("#specify_color_box").slideDown("fast");
}
else{
$("#specify_color_box").slideUp("fast");
}
});
});
【问题讨论】:
标签: javascript jquery toggle forms