gpt4 book ai didi

javascript - 计算元素点击次数并定义最大值

转载 作者:行者123 更新时间:2023-12-02 17:51:21 24 4
gpt4 key购买 nike

我尝试计算元素的点击次数,并在正确的数字中调用一些操作。

var count = 0;
document.getElementById("rolarbaixo").onClick = function(e) {
if( count >= 3 ) {
var elem = document.getElementById("noticia");
elem.setAttribute("style","top: 0px;");
}
else {
count ++;
}
};

当我在链接“rolarbaixo”中单击 3 次时,div“noticia”设置了“top: 0px;”,但这不起作用。为什么?

最佳答案

count++ 应该是 count++。如果按 F12,您将能够访问开发人员工具和 debug the javascript

关于javascript - 计算元素点击次数并定义最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21338038/

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