每当用户使用 JQuery 单击我的 html 选择选项之一时,我想打开一个新页面。按照 JQuery 教程中的示例,我构建了如下所示的代码。但是,当我单击任何选项时,页面无法打开
$('#Databases').change(function () {
$.post("test.php");
});
其中Databases
是我的选择ID。为什么我打不开test.php
?有解决办法吗?
open()
方法将打开一个新的浏览器窗口。如果您想在同一浏览器窗口中打开新页面,我建议您使用 window.location.assign()
.
例:
$('#Databases').change(function () {
window.location.assign("test.php");
});
参考
你应该使用window.location
或window.open
:
$('#Databases').change(function (e) {
window.open("testScript.php"); // if you want to open another window
// window.location.href = "testScript.php"; //if you want to open in same window
});
使用 window.open 函数:
$('#Databases').change(function () {
window.open("test.php");
});
因为$.post
只是$.ajax
type='post'
- 异步调用。您可以在该功能done
或success
部分中打开新窗口,但我想这不是您想要的。