0

尝试在选择选项上显示图像的预览。下面的代码在 Firefox 中运行良好,但在 Internet Explorer 中运行良好。

我试图发出警报以显示图像的 scr,它在 Firefox 中显示正确的路径,但在 IE 中显示 garbeg 值,而不是 1.jpg 它显示 %01.jpg

知道如何让它在 IE 上运行吗?

newAray 包含图像名称,如 1.jpg ,2.jpg ....

在此处输入图像描述

这是代码:

   <form  id = " delete_image" action="DeleteImages.jsp" method="post" >
<select  id = "image_id_delete"  name= "image_id_delete"  onchange="CngColor(this);" style="color:#4B616A; background-color:#eaeced; border:1px solid #939fa4; height:26px; width:120px; padding-bottom: 4px; text-align:center;">
<option value=""><---Select---></option>
<%

for(int i=0;i<newAray.size();i++) 
{ %> 


<option > <%= newAray.get(i) %></option>
<% 
}

%>
</select>


&nbsp; &nbsp; &nbsp;
<img id="Img1" src="images/1.jpg" width=100 height=100 >

<input type="submit" value= "Delete" style="color:#ffffff; background-color:#939fa4; border:1px solid #4b616a; font-weight: bold; height: 27px; padding-bottom: 3px; cursor: pointer;" >


</form>

Javascript:

    function CngColor(obj){
index=obj.selectedIndex;
alert(""  + document.getElementById('Img1').src);
document.getElementById('Img1').src= 'images/'+obj.options[index].value;
}
4

1 回答 1

0

谢谢大家的回复。得到了答案:

function CngColor(obj){
index=obj.selectedIndex;

document.getElementById('Img1').src= 'images/'+obj.options[index].text;
//cahnged value to text
}

属性"value"在某些版本的 Internet Explorer 中不起作用,因此请从"text"Option 对象的字段中读取值。

于 2013-05-21T06:38:19.233 回答