html图片的onclick事件无反应?

<!DOCTYPE html>现在在初学html<html><head> <script> alert("start"); function test() { alert("test"); } </script></head><link rel="stylesheet" type="text/css" href="hexagon.css"><body><!--这是一个正六边形--><div class="hexagon_father"> <div class="hexagon_child"> <div class="hexagon_childchild"> <img src="forest.png" style="cursor:pointer" οnclick="alert('ok')"> </div> </div></div></body></html>如上是html源代码,现在在初学html,想做一个图片触发的功能现在都出问题,求助大神如何处理,图片是嵌在一个六边形里面的,鼠标指向图片时可以变成手型

本身就能实现的,style="cursor:pointer"这就是实现你的需求。只是需要点击图片弹出ok的话做以下调整:onclick="javascript:alert('ok')"。需要加上javascript:
<div class="hexagon_father">
<div class="hexagon_child">
<div class="hexagon_childchild">
<img src="forest.png" style="cursor:pointer" onclick="javascript:alert('ok')">
</div>
</div>
</div>
温馨提示:内容为网友见解,仅供参考
第1个回答  2020-01-31

把你的代码格式化了下。

几个问题:

1、link 应该写在 head 标签之间。

2、onclick 的 o 有问题。

3、因为看不到最终效果。你的click 是写在图片上的。可能图片被某些标签盖住了,点不到,无法出发相关事件。

本回答被提问者和网友采纳
第2个回答  2020-01-29
删掉你 onclick 周围的字符,重新用键盘输入一遍。
有可能是你复制的代码里有特殊不可见字符了。
相似回答