【发布时间】:2015-04-18 12:48:25
【问题描述】:
我试图计算一个按钮被按下了多少次,但我认为这是不对的,因为即使没有点击“打招呼”按钮,计数按钮也会不断增加
有什么想法吗?
<!DOCTYPE html>
<html>
<head>
<title>JSExample</title>
</head>
<body>
<script type="text/javascript">
function hello() {
alert("Hello there!");
}
var countClicks = 0;
function upCount() {
if(document.getElementById('hello').onclick = "hello()") {
countClicks++;
alert(countClicks);
return true;
} else {
return false;
}
}
</script>
<p><input type="button" name="button" value="Saying Hello" id="hello" onclick="hello();"/></p>
<p><input type="button" name="click" value="Counting" id="click" onclick="upCount();"/></p>
</body>
</html>
【问题讨论】:
标签: javascript html button onclick