我的程序经理是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>
我想在删除之前看到确认窗口.
解决方法
把它放在你的表格中:
<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>