【问题标题】:Javascript code not running properlyJavascript 代码无法正常运行
【发布时间】:2013-10-28 01:01:38
【问题描述】:

我刚刚完成了我的代码,但它没有显示 tick.gif,而是显示了“tick”这个词,上面有一个框。 onmouseover 功能也不起作用。

<!DOCTYPE html>
<html>
<head>
<title>Changeup test</title>
</head>
<body>
<img scr="tick.gif" alt="tick" onmouseover="this.scr='tick2.gif';
"onmouseout="this.gif='tick.gif';" />
</body>
</html>

【问题讨论】:

  • 有趣的事实...您不需要this 来引用处理程序属性中的元素属性。您可以将属性视为变量。 onmouseover="src='tick2.gif';"

标签: javascript html image onmouseover onmouseout


【解决方案1】:

标签的源属性在您上面粘贴的代码中拼写错误。它必须是 src。

<!DOCTYPE html>
<html>
  <head>
  <title>Changeup test</title>
  </head>
  <body>
    <img src="tick.gif" alt="tick" onmouseover="this.src='tick2.gif'; "onmouseout="this.src='tick.gif';" />
  </body>
</html>

【讨论】:

  • this.gif 也应该是this.src
  • 是的,很抱歉没有第一次看到。没有属性.gif。您应该改用.src。感谢您发现它。
猜你喜欢
  • 2011-12-16
  • 1970-01-01
  • 2021-11-07
  • 1970-01-01
  • 2021-04-15
  • 1970-01-01
  • 2021-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多