我有一个确认弹出窗口,说不确定在哪里应该说消息‘按下OK或取消’,然后段落应该改变为“你点击了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>
发布于 2017-03-12 02:33:05
您的单击引用了错误的函数:
<button onclick="confirm()">Click Me</button>应该是
<button onclick="confirmFunction()">Click Me</button>https://stackoverflow.com/questions/42739003
复制相似问题