gpt4 book ai didi

javascript - JavaScript 运算符的建议

转载 作者:行者123 更新时间:2023-11-30 17:08:44 25 4
gpt4 key购买 nike

我正在尝试使用 JavaScript 制作一个应用程序。

应用应该有一个加号、一个减号按钮和一个清除按钮。在中间应该有一个输入,其中将出现一个数字。

应用程序将从 1000 开始,加号将增加 1000,减号按钮将减少 1000,清除按钮将重置应用程序。应用中的最小数量应为 1000。

我已经找到了大部分,但是加号按钮没有正常工作,我无法让应用程序将 1000 作为最小值,它只是继续减号。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Application</title>
</head>
<style>
#application{
margin-top: 300px;
margin-left: 300px;
}
input[type=button]{
cursor: pointer;
padding: 10px 30px;
border-radius: 1px;
font-size: 2.5em;
}
input[type=text]{
padding: 10px 30px;
border-radius: 1px;
text-align: center;
font-size: 2.5em;
}
</style>
<body>
<section id="application">
<input id="substraction" type="button" value="-" onclick='substraction();'/>
<input id="number" value="1000" type="text">
<input id="addition" type="button" value="+" onclick='addition();'/>
<input type="button" value="Clear" onclick='clearText();'/>
</section>
<script>
function substraction(){
document.getElementById("tall").value -= 1000;
}
function addition(){
var numb = document.getElementById("number").value;
var add = 1000;
var total = number + add;
document.getElementById("tall").value = total;
}
function clearText(){
document.getElementById("number").value = "1000";
}
</script>
</body>

最佳答案

只需使用 number <input> 相反:

function clearText(){
document.getElementById("myNumber").value = 1000;
}
<input id="myNumber" type="number" step="1000" min="1000" max="1000000" value="1000">
<input type="button" value="Clear" onclick='clearText();'/>

这样,您可以只使用 step , min , 和 max 指定输入行为的属性。

关于javascript - JavaScript 运算符的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27424108/

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