到目前为止我已经做到了:
<form>
Select image:
<select id="artwork">
<option>image 1</option>
<option>image 2</option>
<option>image 3</option>
<option>image 4</option>
<option>image 5</option>
</select>
<input id="turnin" class="turnin" type="button" value="Upload" onclick="start()">
</form>
<script type="text/javascript">
<!--
function start()
{
var select=document.getElementById('artwork');
var selected = select.options[select.selectedIndex].text;
$('#blah').prepend('<img id="image_2" src="image2.jpg" />');
};
//-->
</script>
但是,我想要
$('#blah').prepend('<img id="image_2" src="image2.jpg" />');
部分仅在选项为“image 2”时生效。有办法做到这一点吗?
编辑:如果有一种方法可以让按钮只工作一次,也会很有帮助。
最佳答案
function start() {
var select = document.getElementById('artwork');
if($(select).val() === 'image 2') {
$('#blah').prepend('<img id="image_2" src="image2.jpg" />');
}
}
关于javascript - 如何在特定情况下表现某事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17218419/