gpt4 book ai didi

javascript - 我无法将确认框与段落标签链接

转载 作者:行者123 更新时间:2023-12-03 02:10:29 25 4
gpt4 key购买 nike

如果用户在确认框中单击“确定”,他就可以访问该网站,否则他将被拒绝。如何将innerHtml文本传递到段落标记中?

// Confirm Box
if(confirm("Please confirm that you are a citizen of India.") == true)
{ document.getElementbyId("demo").innerHTML = "Welcome to our Website!";
}
else
{ document.getElementbyId("demo").innerHTML = "Access Denied";
}
<!DOCTYPE html>
<html>
<head>
<title>PromptBox, ConfirmBox, AlertBox</title>
</head>
<body>

<p id="demo" ></p>
</body>
</html>

最佳答案

试试这个。您犯的错误是您在 document.getElementById("") 中输入了 b 而不是 B。请记住,javascript 是区分大小写的语言。

// Confirm Box
if(confirm("Please confirm that you are a citizen of India.") == true)
{
document.getElementById("demo").innerHTML = "Welcome to our Website!";
}
else
{
document.getElementById("demo").innerHTML = "Access Denied";
}
<!DOCTYPE html>
<html>
<head>
<title>PromptBox, ConfirmBox, AlertBox</title>
</head>
<body>

<p id="demo"></p>
</body>
</html>

关于javascript - 我无法将确认框与段落标签链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49596732/

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