我不想使用双击功能,相反,我只是 想在用户单击两次而不是单击两次时运行下面的buttonOnClick(),请帮助我学习编码
<button onclick="buttonOnClick();" onmouseover="mouseOver();" onmouseout="mouseOut();">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
<br>
</div>
功能buttonOnClick()
{
window.open('https://www.youtube.com/channel/UCXE6pw29K2lHS_2fB8LeU1Q?sub_confirmation=1','_blank');
setTimeout(aTagChange, 12000);
}
答案 0 :(得分:4)
设置变量prevClick
,然后更新并检查它:
var prevClick = false;
function buttonOnClick() {
if (prevClick) {
window.open('https://www.youtube.com/channel/UCXE6pw29K2lHS_2fB8LeU1Q?sub_confirmation=1','_blank');
setTimeout(aTagChange, 12000);
} else {
prevClick = true;
}
}
答案 1 :(得分:3)
您可以使用ondblclick
function func(){
console.log("double clicked");
}
<button ondblclick="func()">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
Boolean
来检查其是否单击过一次
let clicked = false;
function func(){
if(clicked === false){
clicked = true;
return false;
}
else clicked = false;
console.log("clicked second time");
}
<button onclick="func()">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>