[英]javascript alert before php code
page:content display.php 页面:content display.php
<td width="100"><a onclick="return confirmSubmit()" href="delete.php?id=<?php echo $row['id']; ?>&table=labour_details&return=content_display.php"><img src="../images/delete.png" border="0" alt="delete"></a></td>
page:delete.php 页:delete.php
if(isset($_GET['id']) && isset($_GET['table']))
{
$id=$_GET['id'];
$tablename=$_GET['table'];
$return=$_GET['return'];
if($tablename=="labour_details")
{
$sql=mysql_query("SELECT * FROM `labour_details` WHERE `id`='$id'");
$row_1=mysql_fetch_array($sql);
$labour_name= $row_1['labour_name'];
if($labour_name!="")
{
$str=mysql_query("DELETE FROM `labour_details` WHERE `id`='$id'");
if($str)
{
header("location:$return?msg=Record Deleted Successfully!&id=$id");
}else{
echo "Problem in deleting :";
}
}
}
}
my problem is where to add alert so that before deleting record it show javascript massage if allow then it will delete record. 我的问题是在哪里添加警报,以便在删除记录之前显示javascript按摩(如果允许),它将删除记录。
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to Delete this Entry?");
if (agree)
return true ;
else
return false ;
}
此行将显示重定向之前的确认对话框。
<a onclick="return confirm('Are You sure?')">...</a>
First you need to create the confirmSubmit() function 首先,您需要创建confirmSubmit()函数
<script>
function confirmSubmit()
{
if (confirm('Are you sure you want to delete this?'))
{
return true;
}
return false;
}
</script>
Then you attach that to your A tag, as you have done.. 然后,将其附加到您的A标签上,就像完成操作一样。
<a href="..." onclick="return confirmSubmit();">blah</a>
You're probably looking for confirm . 您可能正在寻找确认 。
Then, the body of the confirmSubmit
function would look something like: 然后,
confirmSubmit
函数的主体将类似于:
function confirmSubmit() {
return confirm ("Are you sure you want to do this?");
}
This works due to how event handlers work in javascript. 由于事件处理程序在javascript中的工作方式,因此可以正常工作。 Confirm returns
true
when the user clicks OK and false
when they click Cancel. 当用户单击“确定”时,Confirm返回
true
,而当单击“取消”时,则返回false
。
By returning a true
/ false
value from an event handler function you tell the window whether to keep processing that event. 通过从事件处理程序函数返回
true
/ false
值,您可以告诉窗口是否继续处理该事件。 Returning false
(which happens when the user clicks Cancel) tells the browser to stop processing the event and not follow the link. 返回
false
(在用户单击“取消”时发生),指示浏览器停止处理事件,而不关注链接。
<td width="100"><a onclick="confirmSubmit(id)"><img src="../images/delete.png" border="0" alt="delete"></a></td>
function confirmSubmit(delete_id)
{
var r=confirm("Are you sure you want to delete?");
if(r==true)
{
window.location.href = "delete.php?id="+delete_id"; ?>&table=labour_details&return=content_display.php"
}
}
<a onclick="return confirm('Are you sure?')" href="delete.php">delete</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.