javascript - 为什么 javascript 函数在 html 参考中不起作用?
问题描述
function ClearAll() {
localStorage.clear();
doShowAll();
}
<?php
session_start();
header('Location: index.html');
?>
<html>
<head>
<meta charset="UTF-8">
<title>shopping cart</title>
<script src="Storage.js"></script>
<link rel="stylesheet" href="StorageStyle.css">
</head>
<body>
<script>ClearAll();</script>
</body>
</html>
<?php
$_SESSION['loggued_on_user'] = NULL;
?>
我想注销并同时ClearAll
从 js 文件执行功能。但是我在没有清理 js 中的内容的情况下获得了注销。
解决方案
header('Location: index.html');
当您发出 HTTP 重定向时,大多数客户端(包括所有主流浏览器)都会透明地跟随它。
HTTP 响应的正文(这是您的 HTML 文档,其中包含 JavaScript)仅由不自动遵循重定向的客户端使用。
由于不呈现 HTML 文档,因此不执行 JavaScript。
您可能应该使用事件处理程序运行 JS,该click
事件处理程序侦听用户在上一页单击以启动注销的按钮。
推荐阅读
- javascript - 声音结束时的 Adobe Animate HTML5
- java - Java while 循环堆栈 - 阻塞
- laravel - 如果任何一个用户接到呼叫,立即呼叫用户并断开其他呼叫
- php - apple pay in payfrort return 执行服务失败?
- discord - 如何使用 discord.py 获得加入的用户名和头像 url?
- ios - 分隔线 UITableView
- sas - 选项应该在其中有一个数据文件。它在做什么?
- reactjs - 在 React 组件中导入对象后,TypeScript 给出“对象可能未定义”错误
- r - 根据列中的值向数据框中添加/复制行
- python - 为什么 aiohttp 的行为是同步的?