gpt4 book ai didi

javascript - 确认弹出窗口说明未定义且未更改段落

转载 作者:行者123 更新时间:2023-11-30 15:27:39 25 4
gpt4 key购买 nike

我有一个确认弹出窗口,显示未定义,它应该显示消息“按确定或取消”,然后该段落应更改为“您单击确定”或“您单击取消”。

有人可以解释为什么会发生这种情况以及如何解决吗?非常感谢

@charset "UTF-8";
/* CSS Document */

body{
height:1000px;
width:100%;
background:#fff;
margin:0;
}

.divider{
width:100%;
height:auto;
background:#CCC;
display:block;
margin:10px;
}

h2{
font-size:16px;
display:block;
}
#confirm-paragraph{}
#global-variable-paragraph{}
#user-input{}
#expressions{}
#elephant-paragraph{}
#method-1{}
#method-2{}
#ml{}
#litres{}
#conditional-operator{}
#cast-1{}
#cast-2{}
<!-- Checklist: Confirm Example -->
<!-- Checklist: Local Variables -->
<section class="divider">
<h2>Confirm Example</h2>
<button onclick="confirm()">Click Me</button>
<p id="confirm-paragraph">This text should change after clicking the button.</p>
<p style="color:red; font-weight:bold">NOT WORKING Version 1!!!!!!!!</p>
<p>Undefined should instead say "Press OK or Cancel".</p>
<p>And text should change to either "you clicked ok" or "you clicked cancel"</p>
<script>
function confirmFunction() {
var textentry;
var confirmation = confirm('Press OK or Cancel');
if (confirmation == true) {
textentry = "You clicked OK";
} else {
textentry = "You clicked Cancel";
}
document.getElementById("confirm-paragraph").innerHTML = textentry;
}
</script>
</section>

最佳答案

您的点击指向了错误的功能:

<button onclick="confirm()">Click Me</button>

应该是

<button onclick="confirmFunction()">Click Me</button>

关于javascript - 确认弹出窗口说明未定义且未更改段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42739003/

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