javascript - 如何使用js获取post ID php
问题描述
这里我想使用js根据点击按钮显示数据id
我的代码:
var idPost = document.getElementsByClassName("getID")[0];
idPost.onclick = function() {
var GetID = window.location.protocol + "//"
+ window.location.host
+ window.location.pathname
+ '?id=<?php echo $id;?>';
window.history.pushState({ path: GetID }, '', GetID );
}
为什么我的代码不起作用?也许这里有人可以解决我的问题
解决方案
这可能会帮助您:
编辑
location.href
重新加载页面以指示url
var idPost = document.getElementsByClassName("getID")[0];
idPost.onclick = function() {
let id = "<?php echo $id; ?>";
location.href = `?id=${id}`;
}
推荐阅读
- reactjs - 使用 BrowserRouter 单击按钮/链接后如何切换到其他 url
- javascript - 为什么在月份下拉菜单中选择选项 12 时仅不加载 12 月份?
- python - 如何调出类对象?
- c# - LINQ where 子句返回 null
- javascript - 如何将 props 和 function 传递给 react-widow 列表?
- php - 如何在某个段落之后拆分 the_content()
- java - Hibernate 高级映射正确使用@OneToOne
- javascript - Ag 网格 - 主/明细,保持明细行永久打开
- r - 在列表中设置数据框的名称
- excel - Excel:如何根据单元格值的更改创建历史数据