我有一个确认弹出窗口,显示未定义的位置应该显示“按OK或取消”消息,然后段落应更改为“您单击确定”或“您单击取消”。
有人可以解释为什么会这样,以及如何解决?非常感谢
@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>
答案 0 :(得分:2)
您的点击是指错误的功能:
<button onclick="confirm()">Click Me</button>
应该是
<button onclick="confirmFunction()">Click Me</button>