这里我想使用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}`;
}
关于javascript - php如何使用js获取帖子ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57820710/