有没有办法打印我的 clickCount 而不是使用 标签

发布于 2024-12-04 09:32:29 字数 737 浏览 2 评论 0原文

有没有一种方法可以在不使用输入元素的情况下将我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2024-12-11 09:32:29

您可以将您的价值放入任何元素中。

根据您当前的代码,将您的 input 替换为 div 并使用 innerHTML 而不是 value 即可。

document.getElementById( "counting" ).innerHTML = x;

<div id="counting"></div>

我还可以向您指出 jQuery 的方向吗?这将使您在使用 Javascript 时的生活变得更加轻松。

工作示例

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文