这是我的代码:
//event handler for showing hidden form elements (also ensures only relevant hidden els shown)
//IE needs click event instead of change
$('.select_change').live("change", function(){
//check if value is other
if ($(this).val() == 'other')
$(this).parent().find(".hidden").show();
//if user changes select value from other then hide input
if ($(this).val() != 'other')
$(this).parent().find(".hidden").hide();
return false;
});
HTML如下:
<select id="title" name="title" class="validate[required,funcCall[validateNotDefault]] select_change" >
<option value="default" selected="selected">Please choose from options</option>
<option value="yellow">Yellow</option>
<option value="black">Black</option>
<option value="chocoloate">Chocolate</option>
<option value="other">Other</option>
</select>
发布于 2018-07-02 10:08:18
你可以在两种情况下都可以这样做:
$('.select_change').live("change click", function(){
$(this).parent().find(".hidden").toggle($(this).val() == 'other');
});
https://stackoverflow.com/questions/-100000367
复制相似问题