Vấn đề với Mozilla

Nguyễn Kiên Cường
(Steady)

Moderator
Không hiểu sao đoạn script sau chạy tốt với IE mà nếu dùng Mozilla thì lại không chạy nhỉ?

---------------------------------------------

<html>
<head>
<script language="JavaScript" type="text/JavaScript"><!--
function init_item_photo(){
if (document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id]; }
}
oItem_photo = document.getElementById("item_photo");
oItem_photo_arr = new Object();
oItem_photo_arr["White"] = new Image;
oItem_photo_arr["White"].src = "white.gif";
oItem_photo_arr["Yellow"] = new Image;
oItem_photo_arr["Yellow"].src = "yellow.gif";
oItem_photo_arr["Pink"] = new Image;
oItem_photo_arr["Pink"].src = "pink.gif";
} //end for Init_item_photo();
function changeItem(){
oItem_photo.src = oItem_photo_arr[select_color.value].src;
}
//--></script>
</head>
<body onLoad="init_item_photo();">
<img src="white.gif" width="250" id="item_photo">
<select name="select_color" onChange="changeItem();">
<option value="White" selected>white</option>
<option value="Yellow" >yellow</option>
<option value="Pink" >pink</option>
</select>
</body>
</html>
 
Bo+?i vi` no' ko tu+o+ng thi'ch vo+'i Mozilla. Pha?i su+?a la.i la`:
HTML:
<html>
 <head>
  <script language="JavaScript" type="text/JavaScript"><!--
   function init_item_photo() {
    oItem_photo_arr = new Object();
				oItem_photo_arr["White"] = new Image;
				oItem_photo_arr["White"].src = "white.gif";
				oItem_photo_arr["Yellow"] = new Image;
				oItem_photo_arr["Yellow"].src = "yellow.gif";
				oItem_photo_arr["Pink"] = new Image;
				oItem_photo_arr["Pink"].src = "pink.gif";
			} //end for Init_item_photo();
   function changeItem(){
    document.getElementById("item_photo").src = oItem_photo_arr[document.getElementsByName("select_color")[0].value].src;
   }
   window.onload=init_item_photo();
  //--></script>
 </head>
 <body>
  <img src="white.gif" width="250" id="item_photo">
  <select name="select_color" onChange="changeItem();">
   <option value="White" selected>white</option>
   <option value="Yellow" >yellow</option>
   <option value="Pink" >pink</option>
  </select>
 </body>
</html>
Thu+' nha^'t, Mozilla ko the^? du`ng luo^n te^n element nhu+ kie^?u oItem_photo_arr[select_color.value].src ---> pha?i su+?a la.i tha`nh document.getElementsByName("select_color")[0].value.
Thu+' 2, ne^'u du`ng onLoad be^n trong body tre^n Mozilla no' se~ ko cha.y ---> be^n trong ddoa.n <script></script> pha?i the^m va`o cuo^'i window.onload=init_item_photo()
 
Back
Bên trên