javascript - 如何在 PHP 文件中调用 JS 函数
问题描述
我有一个项目,我可以在网站上上传特定的 excel 文件。excel 文件在网站上显示为 html 表格。表格下方是一个按钮,用于将表格上传到数据库中。因此,我将表格单元格保存在一个数组中(在 JS 函数中)。最后,我将数组传递给第二个 php 文件,在那里我将数组数据上传到数据库中。在上次上传时,我想显示一个弹出窗口。我有这些文件:
上传.php
if (isset($_FILES['file']) && !empty($_FILES['file'])) {
//show excel file as table on website
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<button id="exBtnHoch" name="exBtnHoch" onclick="saveInArray()" type="button" class="btn btn-success btn-block">Excel-Datei hochladen</button>
</br></br></br></br></br></br>
</form>
}
excelEinlesen.php
include "pop_up.php";
if(isset($_POST['daten'])){ //checks if array is passed
//if successfull then do something like:
echo '<script type="text/javascript">showPOP_UP();</script>';
}
//EDIT
function a (){} //they are called in the if-part
function b (){}
编辑:pop_up.php:HTML代码
<!doctype html>
<html lang="de">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script type="text/javascript" src="js/excelEinlesen.js"></script>
</head>
<body>
<div class="modal fade" id="pop_upHochgeladen" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Speichern</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Die Daten des Mitarbeiters wurden erfolgreich in die Datenbank geschrieben.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" onClick="geheZuHome()">Zurück zur Startseite</button>
<button type="button" class="btn btn-warning" onClick="window.location.href=window.location.href">Weitere Datei hochladen</button>
</div>
</div>
</div>
</div>
</body>
</html>
和
excelEinlesen.js
function saveInArray(){
//save table cells in array
//at the end pass array to excelEinlesen.php
}
function showPOP_UP(){
$('#pop_up').modal('show');
}
我试图回应它并搜索整个互联网,但没有任何令人满意的解决方案。首先在 upload.php 中有第二个 onclick 并且它有效,但我想在没有 onclick 的特定情况下调用 JS 函数。
我不知道这是否有问题,但我的文件有不同的文件夹:“js”和“php”。
解决方案
推荐阅读
- android - 可选择在应用中使用 Cloud Firestore
- php - php 和 mongodb - 将结果作为公共数组集合获取
- python-3.x - Python 异常导入问题
- php - Laravel 存储链接不适用于生产
- webpack - 即使在生产模式下构建,VueJS 也会显示“开发模式”消息
- graphql - 尝试在 GraphCMS api 上连接时出现 Gatsby Graphql 问题
- varnish - 在默认端口 6081 上清漆
- ruby - kubeclient create_namespace NoMethodError
- html - NVDA 和 JAWS 在 Textarea 中禁用输入
- c# - 如何使用 CoreCursorType.Custom 在 C# UWP 中创建自定义光标?