gpt4 book ai didi

JavaScript 计数器不会超过 1

转载 作者:行者123 更新时间:2023-11-28 13:49:11 25 4
gpt4 key购买 nike

因此,当我单击“添加”按钮时,它会检查输入字段中是否有文本,然后为其创建一个 div,然后向计数器添加 +1。问题出在计数器上;它只会添加 +1,然后再次单击时不会执行任何操作。当我删除一个 div 时,它的值是 -1 就好了。所以是的,不会超过 1 或 -1。

网站:

http://web-owl.com/todo/

功能:

 function validateForm() 
{
var x=document.forms["forming"]["texting"].value;
if (x==null || x=="")
{
alert("Get it together! You need to have text in there!");
return false;
}
else
{

var clone = $('#theDiv')
.clone()
.attr('id','')
.show()
.append(
$('<div>').html(
$('#textI2').val()
).addClass('futureEditor')
);
$('#hold').append(clone)
var x = 0;
x += 1;
document.getElementById( "clicked" ).value = x;
return false;
}

}

点击的链接:

<form id="forming" name="forming"  onsubmit="return validateForm()" method="post">

计数器:

<p>You have <input id="clicked" size="3" onfocus="this.blur();" value="0" > Stuffs. </p>

最佳答案

使计数变量全局化

var count = 0;
function validateForm() {
var x = document.forms["forming"]["texting"].value;
if (x == null || x == "") {
alert("Get it together! You need to have text in there!");
return false;
}
else {

var clone = $('#theDiv').clone().attr('id', '').show().append(
$('<div>').html(
$('#textI2').val()).addClass('futureEditor'));
$('#hold').append(clone)
count++;
document.getElementById("clicked").value = count;
return false;
}

}

关于JavaScript 计数器不会超过 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11985731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com