有没有办法打印我的 clickCount 而不是使用 标签
有没有一种方法可以在不使用输入元素的情况下将我的 clickCount 打印到页面?
这是我的代码,以便更好地理解:
<!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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将您的价值放入任何元素中。
根据您当前的代码,将您的
input
替换为div
并使用innerHTML
而不是value
即可。我还可以向您指出 jQuery 的方向吗?这将使您在使用 Javascript 时的生活变得更加轻松。
工作示例。
You can put your value into any element.
Given your current code, replacing your
input
with adiv
and usinginnerHTML
instead ofvalue
will work.Might I also point you in the direction of jQuery. This will make your life a lot easier whilst working with Javascript.
Working example.