javascript - How do I include Javascript inside PHP?
问题描述
I'm trying to write some Javascript inside PHP, I made a simple button that takes you to the previous page. The button is showing but the functionality of the button isn't working. This is the code I have.
<?php
$product;
if (empty($product))
{
echo
'
<script>
function myFunction() {
header("location:".history.go(-1));
}
</script>
<button onclick=myFunction()>Click me</button>
';
exit();
}
I go to my local server to the file where this code is and except it to work but it doesn't. For example, I go to http://127.0.0.1/test1.php
where there is is a button (which works perfectly) that takes you to http://127.0.0.1/test2.php
(where this this piece of code is). When I press the 'Click me' button, nothing happens. I'm wondering what I'm doing wrong? Or is it because It's local that the problems are caused? I've tried this in Chrome and Safari.
解决方案
您有错误的代码历史记录:
function myFunction() {
window.history.go(-1);
}
推荐阅读
- autodesk-forge - 在 Forge 中使用 eTransmit
- python - 如何让语音延迟消失?
- firebase - Flutter 中的单元测试 firebase 抛出异常“没有创建 Firebase App '[DEFAULT]' - call Firebase.initializeApp()”
- c# - 如何在无效的表单字段中显示错误消息?
- grails - 记录器在打印对象的 grails 4 中抛出异常
- node.js - 如何使用节点 js 服务器连接到 MongoDB Atlas,使用 .env 文件环境
- python - 如何在一段时间后执行命令 discord.py
- c - 如何使用 C 中的指针检测缓冲区溢出?
- c# - 具有 App Config 和托管标识的 Azure 函数 - 如何在本地调试
- git - 如何计算提交之间特定作者更改的总行数?