javascript – window.location =”不起作用;

$(document).ready(function() {
  $("#submit").click(function() {
    var value = document.getElementById("txt_sketch_no").value;
    var process_id = document.getElementById("process_id").value;
    var length = value.length;
    if (length <= 0) {
      alert("Please Enter the sketch card");
      window.location = 'sketch_screen.php';
    } else {
      window.location = 'dws_Support.php';
    }
  });
});
<form action="" method="post" autocomplete="off">
  <div class="container">
    <div class="alert alert-success" id="alert_box">
      <input type="hidden" name="process_id" id="process_id" value="<?php echo $process_id; ?>">
      <label>Enter the Sketch Card No :</label>
      <input type=text id="txt_sketch_no" name="txt_sketch_no">
      <input type=submit id="submit">

在上面的代码中,我想在Javascript的帮助下重定向页面,但是else部分中的window.location =’dws_Support.php’不起作用,但是当我们在else部分发出警告时,它会显示但不会重定向到’dws_Support.php’.请帮忙.

最佳答案 您不需要使用javascript重定向的表单,问题来自您的属性操作表单,因此请使用以下代码:

<script src="js/jquery.js"></script>
<script>
    $(document).ready(function() {
        $("#submit").click(function() {
            var value = document.getElementById("txt_sketch_no").value;
            var process_id = document.getElementById("process_id").value;
            var length = value.length;
            if (length <= 0) {
                alert("Please Enter the sketch card");
                window.location = 'sketch_screen.php';
            } else {
                window.location = 'dws_Support.php';
            }
        });
    }); 
</script>
</head>
<body style="background-color: #73C5E1" >
        <div class="container">
            <div class="alert alert-success" id="alert_box">
                <input type="hidden" name="process_id" id="process_id" value="12">
                <label> Enter the Sketch Card No : </label>
                <input type="text" id="txt_sketch_no" name="txt_sketch_no">
                <input type = "submit"  id="submit">
            </div>
        </div>
</body>

希望它对你有所帮助.

点赞