jquery and if statment


jquery and if statment

如何以正确的方式进行此过程?如果条件为true,我想使用jquery显示一条消息,如果条件为false,我想显示其他消息。

<?php
if (in_array($id_patients, $rows)) {
  <script>
    jQuery(function () {
      $('#success_insert').fadeIn('slow').delay(5000).fadeOut('slow');
    });
  </script>
<?php
}else{ ?>
  <script>
    jQuery(function () {
      $('#failed_insert').fadeIn('slow').delay(5000).fadeOut('slow');
    });
  </script>
<?php }?>

你知道吗?,请和我分享…

这是jquery

   $("#qsearch").on("submit", function(event) {
                event.preventDefault();
                $.ajax({
                    type: "POST",
                    url: "insert_visiting.php",
                    data: $(this).serialize(),
                    success: function(data) {
 $("#inner_contant").append(data+"<br/>");                    },
                });
            });

})

这是有效的:

<!doctype html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
</head>
<body>
<div id="success_insert" style="display: none;">Success</div>
<div id="failed_insert" style="display: none;">Failed</div>
<?php
$rows = array(1, 2, 3, 4);
$id_patients = 12;
if (in_array($id_patients, $rows)) { ?>
  <script>
    jQuery(function () {
      $('#success_insert').fadeIn('slow').delay(5000).fadeOut('slow');
    });
  </script>
<?php
}else{ ?>
  <script>
    jQuery(function () {
      $('#failed_insert').fadeIn('slow').delay(5000).fadeOut('slow');
    });
  </script>
<?php }?>
</body>
</html>

注意if行上的关闭php标记。