gpt4 book ai didi

javascript - checkRiddle() 在 showdialog() 中间?

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:06 25 4
gpt4 key购买 nike

</head>

<body onLoad="MM_preloadImages('images/images/sixth3_over.jpg')">
<div id="container">
<div id="background"></div>
<div id="dialog">
<p>Test!</p>
</div>
<div id="button" function onClick="showDialog(); typeWriter; cursor.play(); checkRiddle()">
<img src="images/images/sixth3.jpg" alt="" width="126" height="210" id="Image1" onMouseOver="MM_swapImage('Image1','','images/images/sixth3_over.jpg',1)" onMouseOut="MM_swapImgRestore()"/>
</div>


</div>

</body>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">

var counter = 0;

function typeWriter(el,i,str) {
if (typeof str == "undefined") var str=$(el).text();
if (typeof i == "undefined") var i=0;
var text = str.slice(0, ++i);
if (text != str){
setTimeout(function(){typeWriter(el,i,str)}, 40);
}
$(el).text(text);
};

function checkRiddle(){
var riddle = prompt('What is the answer?')
if(riddle.toLowerCase()== "reduce"){
window.location = "riverend.html";
}
else if(riddle.toLowerCase()== "reuse"){
window.location = "riverend.html";
}
else if(riddle.toLowerCase()== "recycle"){
window.location = "riverend.html";
}
else {
alert("That's not right....")
}

function showDialog() {
if (counter == 0) {
$("#dialog p").html("Test 2");
typeWriter('#dialog p');
} if (counter == 1) {
$("#dialog p").html("Test 3");
typeWriter('#dialog p');
}
if (counter == 2) {
$("#dialog p").html("Test 4");
typeWriter('#dialog p');
}
if (counter == 3) {
checkRiddle();
}
//increase counter by 1
counter++;
}

</script>

我想在第三次单击按钮 div 时创建 checkRiddle() 函数。

但是,一旦我添加了 checkRiddle() 函数,showDialog() 也会停止工作,我无法再点击按钮。

最佳答案

乍一看,似乎是格式问题...缺少 } 和 ;

function checkRiddle(){
var riddle = prompt('What is the answer?');
if(riddle.toLowerCase()== "reduce"){
window.location = "riverend.html";
}
else if(riddle.toLowerCase()== "reuse"){
window.location = "riverend.html";
}
else if(riddle.toLowerCase()== "recycle"){
window.location = "riverend.html";
}
else {
alert("That's not right....");
}
}

关于javascript - checkRiddle() 在 showdialog() 中间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792373/

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