[英]Javascript after X click in button to go
How can i make the function for this button: 如何为此按钮创建功能:
<input id="btntest" type="button" value="Check" onclick="return btntest_onclick()" />
so that after 30 click's redirects me to a different page. 所以30点击之后会将我重定向到另一个页面。
Declare a global variable: 声明一个全局变量:
var counter = 0;
function btn_test_onclick(){
if(counter === 30){
window.location.href = 'http://www.google.com';
} else {
counter++;
}
}
Here's some info on window.location 这是关于window.location的一些信息
<script>
var count = 0;
function btntest_onclick(){
count++;
if(count ==12){
window.location.href = 'http://www.google.com';
}
}
</script>
You can do like this 你可以这样做
<input id="btntest" type="button" value="Check" onclick="return btntest_onclick()" />
<script>
var btntest_onclick = (function () {
var i = 1;
return function () {
alert(i);
i++;
if(i>30){
window.location = "www.google.com";
}
}
})();
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.