gpt4 book ai didi

javascript - 自动化检查过程

转载 作者:行者123 更新时间:2023-12-01 01:14:10 27 4
gpt4 key购买 nike

下面的代码返回“偶数”或“奇数”,但我必须始终更改,如何让他检查 25 到 115 并在页面正文中显示结果?

<html>
<title>FrontPage</title>
</head>
<body>
<form method="post" name="Form1" onsubmit="Check();">
<input type="submit" value="Submit" name="bSubmit"></p>
</form>

<script type="text/javascript">
function Check() {
var n = "26";
var finish = n/2;

if(n & 1){
alert("Impar");
} else {
alert("Par");
}
alert(finish);
}
</script>
</body>
</html>

最佳答案

var btn = document.querySelector('#btn');
var result = document.querySelector('#result');

btn.addEventListener('click', function() {
for (var i = 25; i <= 115; i++) {
var li = document.createElement('li');
li.innerText = i.toString() + ' - ' + ((i & 1) ? 'Impar' : 'Par');
result.append(li);
}
});
<input id="btn" type="submit" value="Submit" name="bSubmit">
<ul id="result"></ul>

关于javascript - 自动化检查过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54910604/

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