【发布时间】:2016-10-20 06:09:30
【问题描述】:
我正在使用此代码根据下拉选择显示和隐藏图像:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.pack.js"></script>
</head>
<body>
<select id="my_select" name="select_name" class="order_form_select">
<option data-img="" value="" disabled selected>Please select ↓</option>
<option data-img="1.jpeg" value="first">First</option>
<option data-img="2.jpeg" value="second">Second</option>
<option data-img="3.jpeg" value="third">Third</option>
</select>
<img id="order_form_image" src="">
<script>
document.getElementById("my_select").onchange = showFormatImage;
function showFormatImage() {
$("#order_form_image").attr('src', $('select[name=select_name] option:selected').attr('data-img'));
$('#img_src').html($("#order_form_image").attr('src'));
return false;
}
</script>
</body>
</html>
效果很好。但是在 Firefox 48.0.1 上,如果没有下拉选择,我会得到一个损坏的图像图标。截图如下:
为什么?我能做些什么来预防它?
【问题讨论】:
标签: javascript jquery html firefox