我有一个简单的表单,仅包含一个用于下载文件的按钮。这是代码:
<form method='post' action='download.php?file=file.txt' name='form1'>
<button type='submit'>Telecharger</button>
</form>
Download.php 是一个小的 php 文件,其 header 用于下载,如下:
<?php
$filename=$_GET['file'];
header('Content-Type: text/plain');
header("Content-disposition: attachment;filename=$filename");
readfile($filename);
?>
我想做的是在用户单击按钮或表单后隐藏它。到目前为止,我已经尝试使用 css 和 javascript 监听器,但到目前为止没有任何效果。
当我单击按钮时,它会下载文件但不会隐藏按钮。
提交表单后如何隐藏按钮?
最佳答案
您可以使用 JavaScript:
<form method='post' action='download.php?file=file.txt' name='form1'>
<button onClick='this.style.display = "none";' type='submit'>Telecharger</button>
</form>
这将在单击时隐藏您的按钮。 Here是一把 fiddle 。
关于javascript - 单击后尝试隐藏 "download"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43761995/