gpt4 book ai didi

javascript - 增加图像映射点击的变量数

转载 作者:行者123 更新时间:2023-11-30 13:17:55 25 4
gpt4 key购买 nike

我有一个图像映射,想跟踪它在 javascript 中被点击的次数,但我不知道如何记录点击次数。

<p>
<img src="image.png" alt="missing" width="396" height="376" border="0" usemap="#thatPageMap" />

<map name="imageMap" id="thatPageMap">
<area shape="poly" coords="0,376,-3,269,50,251,60,234,71,225,76,192,69,178,44,127,50,82,73,62,94,48,69,46,108,30,145,20,162,29,162,16,183,34,193,41,228,35,247,38,225,47,242,47,279,53,306,78,324,117,326,150,335,179,327,200,327,221,351,234,357,263,393,275,394,378" href="thatpage.com" alt="Refresh" />
</map>
</p>

上面是图像映射,下面是javascript和带有计数ID的段落。

<script type="text/javascript">

var count;

document.getElementById("counted").innerHTML = "This has been clicked " + count + " times.";

</script>

<p id="counted"></p>

每次单击图像映射时如何增加变量计数?

最佳答案

例如像这样:

<script type="text/javascript">
var count = 0;
function updateCounter( ) {
count++;
document.getElementById("counted").innerHTML = "This has been clicked " + count + " times.";
}
</script>

<p id="counted"></p>

<map name="imageMap" id="thatPageMap" onclick="updateCounter()">
<area shape="poly" coords="0,376,-3,269,50,251,60,234,71,225,76,192,69,178,44,127,50,82,73,62,94,48,69,46,108,30,145,20,162,29,162,16,183,34,193,41,228,35,247,38,225,47,242,47,279,53,306,78,324,117,326,150,335,179,327,200,327,221,351,234,357,263,393,275,394,378" href="thatpage.com" alt="Refresh" />
</map>

关于javascript - 增加图像映射点击的变量数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11332174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com