Is there a way of printing my clickCount to the page without using an input element?
Here is my code for a开发者_开发技巧 better understanding:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vote!</title>
<script type="text/javascript">
function countClicks() {
var x = 0;
x += 1
document.getElementById( "counting" ).value = x;
var clickLimit = 1; //Max number of clicks
if(x>=clickLimit) {
}
else
{
ClickCount++;
return true;
}
}
</script>
</head>
<body>
<input type="button" value="VOTE" name="clickOnce" onclick="return countClicks();" /><br>
<input id="counting" type="text">
</body>
</html>
You can put your value into any element.
Given your current code, replacing your input
with a div
and using innerHTML
instead of value
will work.
document.getElementById( "counting" ).innerHTML = x;
<div id="counting"></div>
Might I also point you in the direction of jQuery. This will make your life a lot easier whilst working with Javascript.
Working example.
精彩评论