我的程序经理是php中的QR码。我有我的QR码列表,并有(以及其他选项)删除QR码的选项。当我点击删除时,我想在javascript中显示确认消息。当我点击保存时,我不需要确认。
我的表格:
<form method="post" enctype="multipart/form-data">
(...)
<input type="submit" name="save_edit" value="SAVE" />
<input type="submit" name="delete" value="Delete QR-code" />
</form>
我的代码:
if(isset($_POST['delete']))
{
$id = $_SESSION['tmp_id'];
$query = mysql_query("SELECT name_file FROM $tbl_query WHERE id='$id'");
if(mysql_num_rows($query) > 0)
{
while($row = mysql_fetch_array($query))
{
$result = mysql_query("DELETE FROM $tbl_query WHERE id='$id'");
unlink("img_qr/".$row["name_file"]);
if($result)
{
$_SESSION['alert_type']=1;
$_SESSION['msg_alerr']= "QR-code delete!";
}
else
{
$_SESSION['alert_type']=-1;
$_SESSION['msg_alert']= "Error!";
}
}
}
}
我尝试了javascript,但它不起作用:
<script type="text/javascript">
function confirm() {
var r=confirm('Are you sure you want to delete??');
if (r==true)
{
//delete file...
}
}
</script>
我希望在删除之前看到确认窗口。
答案 0 :(得分:16)
把它放在你的表格中:
<form method="post" enctype="multipart/form-data" onsubmit="return confSubmit();">
你的javascript函数应该是
<script type="text/javascript">
function confSubmit() {
var r=confirm('Are you sure you want to delete??');
return r;
}
</script>