简体   繁体   English

JavaScript无法在Internet Explorer 9中运行

[英]JavaScript not working in Internet Explorer 9

Trying to show the preview of images on select option.Below code is working fine in Firefox but not in Internet Explorer. 尝试在选择选项上显示图像预览。下面的代码在Firefox中工作正常,但在Internet Explorer中无法正常工作。

i have tried to put an alert to display the scr of image , it shows correct path in Firefox but in IE it shows garbeg value like instead of 1.jpg it shows %01.jpg 我试图发出警报以显示图像的scr,它在Firefox中显示正确的路径,但是在IE中,它显示的是garbeg值,而不是1.jpg,而是显示%01.jpg

Any idea how to make it run on IE ? 任何想法如何使它在IE上运行?

newAray contain the image name like 1.jpg ,2.jpg .... newAray包含图像名称,例如1.jpg,2.jpg...。

在此处输入图片说明

This is the code : 这是代码:

   <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 : Javascript:

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

Thanks all for response. 谢谢大家的回应。 Got the answer : 得到了答案:

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

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

Attribute "value" doesnt work in some version of Internet Explorer so read the value from the "text" field of the Option object. 属性"value"在Internet Explorer的某些版本中不起作用,因此请从Option对象的"text"字段中读取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM