2015-06-22 57 views
0

我遇到了onmouseover命令的问题。我在我的HTML代码得到的代码(参见下图)这一点,当我尝试在Safari 7我收到以下错误运行:TypeError:undefined不是对象

TypeError: undefined is not an object (evaluating 'document.images.siz3.src='images/shirts/img_3siz_grey.jpg'') onmouseover

什么问题?我找不到任何可能是错误的。 img应该定义为siz1,不应该吗?

也许有人可以帮忙,我敢肯定答案很简单,我只是没有看到它。

<a href="menu/latein/r-z/vfc/vfc.html" onmouseover="document.images.siz1.src='images/shirts/img_1siz_grey.jpg'" onmouseout="document.images.siz1.src='images/shirts/img_1_siz.jpg'" name="tshirts"> 
 
<img src="images/shirts/img_1_siz.jpg" name="siz1“ alt="Vivat floreat crescat" width="195px" height="135px"></img>

+2

最好添加事件在JavaScript中。内联事件是不好的做法。看看'addEventListener'。另外,请注意引号'“!=”' – elclanrs

+0

检查'img'标签的名称属性,它没有被正确的声明,我也在问题中编辑了它,如果这是问题,你可以再试一次吗? –

+0

啊,谢谢!这是引号...... –

回答

1

看起来问题在这里name="siz1“应该name="siz1"取代"

+1

[正如elclanrs说](http://stackoverflow.com/questions/30977161/typeerror-undefined-is-not-an-object#comment49984847_30977161) - 当张贴其他人的评论作为答案时,它最好把它变成CW。 –

+0

@ T.J。 Crowder我没有看到评论 – ozil

0

你没有用正确的引号关闭 '名称' 标签。

<a href="menu/latein/r-z/vfc/vfc.html" onmouseover="document.images.siz1.src='images/shirts/img_1siz_grey.jpg'" onmouseout="document.images.siz1.src='images/shirts/img_1_siz.jpg'" name="tshirts"> 
 
<img src="images/shirts/img_1_siz.jpg" name="siz1" alt="Vivat floreat crescat" width="195px" height="135px"></img>

0

试试这个代码

<a href="#" onmouseover="change('change')" onmouseout="change('')">Click</a> 
<img id="siz1" src="images/shirts/img_1_siz.jpg" height="200" width="200" /> 
<script> 
    function change(str) { 
     if (str == "") { 
      document.getElementById('r1').src = "images/shirts/img_1_siz.jpg"; 
     } 
     else { 
      document.getElementById('r1').src = "images/shirts/img_1siz_grey.jpg"; 
     } 
    } 
</script> 
相关问题