gpt4 book ai didi

Javascript 事件和 css

转载 作者:太空宇宙 更新时间:2023-11-03 21:28:37 25 4
gpt4 key购买 nike

我有一个输入框和提交按钮作为 html,我想在输入框中输入任何数字,然后如果它是偶数或奇数将显示警告消息。如果它比段落文本颜色之一均匀,则颜色将变为红色,否则为蓝色。这是我的代码:

    <!doctype html>
<html lang="en">
<head>
<script src="jsfile.js"></script>
</head>

<body>
<input type="text" id="inputBox"/>
<button type="button" onclick="AlertBox()">Submit</button>

<p id="p12">My first paragraph</p>
</body>

</html>

外部js文件:

    function AlertBox()
{
var number=document.getElementById("inputBox").value;
if (number / 2 == 0)
{
alert(number + " is even and ok to go.");
document.getElementById("p12").style.color = "red";

} else
{
alert(number + " is not even and not ok to go.");
document.getElementById("p12").style.color = "blue";
}
}

最佳答案

function AlertBox() {
var number = document.getElementById("inputBox").value;
if (number % 2 == 0) {
alert(number + " is even and ok to go.");
document.getElementById("p12").style.color = "red";

} else {
alert(number + " is not even and not ok to go.");
document.getElementById("p12").style.color = "blue";
}
}
<!doctype html>
<html lang="en">

<head>
<script src="jsfile.js"></script>
</head>

<body>
<input type="text" id="inputBox" />
<button type="button" onclick="AlertBox()">Submit</button>

<p id="p12">My first paragraph</p>
</body>

</html>

关于Javascript 事件和 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31079764/

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