【发布时间】:2015-09-28 06:26:53
【问题描述】:
$(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 部分不起作用,但是当我们在 else 部分发出警报时,它会显示但不会重定向到 'dws_Support.php' .请帮忙。
【问题讨论】:
-
使用 window.location.href 或 window.location.assign
-
我的猜测是您在使用 jquery 验证之前提交了表单。尝试先验证它。 stackoverflow.com/a/15072147/797495
-
您确定
if部分中的重定向有效吗? -
这行得通吗?
if (length <= 0) { alert("Please Enter the sketch card"); window.location = 'sketch_screen.php'; return; } else { window.location = 'dws_Support.php'; } -
@MrLister,我使用了 sn-p 函数中的 tidy 按钮。没有注意到它创建了一个错误。显然我不是故意的……
标签: javascript php jquery html