According to w3schools it is okay to use setTimout because it sets an alarm only ONCE. This answer is referenced from: Jquery bind double click and single click separately
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index3</title>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
</head>
<body>
@*<a href="#">Click Me</a>*@
<form>
<input type="checkbox" class="checked" data-bind="checked:isdifferrnt" />
<input type="button" id="btn" value="getValue" />
</form>
<script type="text/javascript">
var DELAY = 700, clicks = 0, timer = null;
//don't use var num use numb
var numb = 0;
$(function () {
$("form input:checkbox").on("click", function (e) {
clicks++; //count clicks
if (clicks === 1) {
timer = setTimeout(function () {
alert("Single Click"); //perform single-click action
if ($("form input:checkbox").is(":checked"))
{
numb++;
}
else
{
numb--
}
clicks = 0; //after action performed, reset counter, setTimeout is running once, so ok to use
}, DELAY);
} else {
clearTimeout(timer); //prevent single-click action
alert("Double Click"); //perform double-click action
clicks = 0; //after action performed, reset counter
}
})
.on("dblclick", function (e) {
e.preventDefault(); //cancel system double-click event
});
});
$("#btn").click(function () {
alert("Value of numb is: " + numb);
});
</script>
</body>
</html>