window.location =''不起作用;

时间:2015-09-28 06:26:53

标签: javascript php jquery html

$(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的帮助下重定向页面,但是其他部分中的window.location = 'dws_Support.php'不起作用,但是当我们在else部分中发出警报时,它会显示但不会重定向到{ {1}}。请帮忙。

4 个答案:

答案 0 :(得分:2)

尝试使用  window.location.href='dws_Support.php'

答案 1 :(得分:0)

您不需要使用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>

希望对你有所帮助。

答案 2 :(得分:0)

这是你的失败:你正在倾听click,但submit形式的事件会制造你的逻辑。这是固定的:

$(document).ready(function() {
  $("form").on('submit', function(e) {
    e.preventDefault();

    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';
    }
  });
});

答案 3 :(得分:0)

很高兴,如果你找到答案,但你的编码没有问题,你只是错过了返回错误;重定向后..

<script src="jquery-1.4.js"></script>
<script type="text/javascript">
<!--
    $(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';
          return false;
        } else {
          window.location = 'dws_Support.php';
          return false;
        }
  });
});
//-->
</script>

希望这可以解决您的问题。 :)