窗口.Location = ''不工作;
window.location = '' is not working ;
$(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='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>
这是您的失败:您正在收听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';
}
});
});
很高兴你找到了答案,但是你的编码没有问题,你只是错过了返回false;重定向后. .
<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>
希望这能解决你的问题。:)
相关文章:
- Windows.Open 在 window.Location 工作时不起作用
- window.location.htm无法在chrome扩展中工作
- Angularjs:了解如何工作$location
- setInterval 或 window.location 在 Opera、IE 和 Safari 中无法正常工作
- window.location在IE9和FF中的工作方式不同
- window.location重定向没有'我不在IE8上工作
- AngularJS $location.path 无法按预期工作
- “window.location.href”是如何工作的
- 如何使 window.location.replace 在 IE 9 中工作
- 如何在没有window.location.reload()的情况下使JavaScript .load工作
- 防止默认停止 window.location.href 工作
- window.location 无法使用 get element by id 来工作
- jquery正在开发网站上工作,但不在生产网站window.location上
- Angular$location change path第二次工作,而不是第一次
- 如何使location.reload()在单击按钮时工作
- .js代码中给出的document.location()函数在Internet Explorer中工作正常,但在Fire
- window.location.htm未按预期工作
- $location.path(“/”);工作不正常
- onclick event window.location.htm无法在mac操作系统上工作
- 试图了解表单是如何工作的,以及为什么document.location.htm无法正常工作