jquery - 包含值时如何在 window.open 中使用 _self?
问题描述
$("#input").keypress(function(event) {
if (event.keyCode == 13) {
window.open("search.html?search=" + $("#input").val()); // here is the location
let searchString = $("#input").val()
localStorage.setItem("search", JSON.stringify(searchString));
}
});
它的工作,但打开另一个选项卡。没有 + $("#input").val());
尝试使用 window.location 和 SO 上的所有其他示例...请帮助
解决方案
你能试试这个:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#input").keypress(function(event) {
if (event.keyCode == 13) {
window.location = "search.html?search=" + $("#input").val(); // here is the location
let searchString = $("#input").val()
localStorage.setItem("search", JSON.stringify(searchString));
}
});
});
</script>
</head>
<body>
<input id="input"/>
</body>
</html>
推荐阅读
- python - 如何遍历文件并删除符合条件的所有行?
- kubernetes - 使用 Ubuntu 16.04 服务器在本地设置的 Kubernetes 集群中运行“Harbor”时出错
- string - 选择表中包含字符串向量中的一个名称的行
- azure - 无法在 terraform 中为 FrontDoor 设置最低 TLS 版本
- java - 为什么这个块在执行过程中没有被执行?
- r - 几个向量之间共享元素的交叉表
- postgresql - 如何在postgresql中按日期和时间查询
- docusignapi - 签名/初始化多个页面 - 多个签名者
- git - 如何默认将 git branch 命令结果输出到标准输出?
- vba - Microsoft Access 报表边距设置不正确,但仅当它们是从我的系统创建时