doucheng9058 2016-03-29 23:41
浏览 48

警报框不能与PHP一起使用

<?php if ($data == "") { ?>
    <script type="text/javascript">
        alert("review your answer1");
        window.location.href = "index1.php";
    </script>
<?php } else { ?>
    <script type="text/javascript">
        alert("review your answer2");
        window.location.href = "index2.php";
    </script>
<?php } ?>

Alert box is not showing in above code as well as page is also not redirecting. What is wrong in it?

  • 写回答

2条回答 默认 最新

  • dosin84644 2016-03-29 23:44
    关注

    Do the other way around:

    <script>
      var data = <?php echo $data; ?>
      if ( data === "" ) {
        alert("review your answer1");
        window.location.href = "index1.php";
      } else {
        alert("review your answer2");
        window.location.href = "index2.php";
      }
    </script>
    
    评论

报告相同问题?