checkdiddle()在showdialog()中间?

时间:2016-01-14 14:44:58

标签: javascript html css html5

</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()也会停止工作,我再也无法点击按钮了。

1 个答案:

答案 0 :(得分:1)

乍一看,看起来像格式问题......缺少}和;

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...."); 
    }
}