Я хочу показать элемент с id=attach
, если выбрана опция с value='Attached File'
. Пожалуйста, помогите мне понять, почему мой код не работает.jQuery: показать/скрыть элемент на основе выбранной опции
Мой код:
<ul class="form-list">
<li id="excellence-form">
<fieldset>
<ul>
<li class="wide">
<label for="excellence:like" class="required"><em>*</em><?php echo $this->__('Initial Data') ?></label>
<div class="input-box">
<select class="required-entry" name="excellence[like]" id="excellence:like">
<option value='0'><?php echo $this->__('Please Choose..');?></option>
<option value='Not Attached' <?php if($this->getQuote()->getExcellenceLike() == 1){echo 'selected="selected"';} ?>><?php echo $this->__('Do Not Attach File');?></option>
<option value='Attached File' <?php if($this->getQuote()->getExcellenceLike() == 2){echo 'selected="selected"';} ?>><?php echo $this->__('Attach File');?></option>
</select>
</div>
</li>
<li id="attach" style="display:none;" >
<label class="required"><em>*</em><?php echo $this->__('Please Attach :') ?><span id='file_upload_text'></span></label>
<div class="input-box">
<input id="file_upload" type="file" name="file_upload" />
</div>
<input id="file_upload_path" type="hidden" name="file_upload_path" class='required-entry' />
<input type="hidden" value='Attached File' name="file_upload_type" class='required-entry' />
</li>
</ul>
</fieldset>
</li>
</ul>
Мой JQuery:
<script type="text/javascript">
$(function() {
$('#excellence:like').change(function(){
if ($(this).val() == "Attached File") {
document.getElementById("attach").style.display="block";
} else {
document.getElementById("attach").style.display="none";
}
});
});
</script>
'#excellence: like' JQuery, вероятно, не понравится этот идентификатор, так как как CSS, так и jQuery используют ':' для псевдо классов и т. п. попробуйте что-то вроде '# excellence-like' – Andy
, почему вы не используете $ ('# attach') для document.getElementById, а не .show() или .hide()? – cptnk