如何在链接上使用php变量来使用onClick事件?

What is the correct way to call the onClick event inside a link sending php variables?

I try to use the following code but is not working.

echo"<td><a href='/ADMIN/deletebooks.php?ID=".$row['ID']." onClick='return confirm('Do you really want to delete this book?')''>Delete</a></td>";

My javascript function is as follow:

<script type="text/javascript">
function ConfirmChk(){
{
 if(confirm("Do you  really want to delete this book?");
  return true;
 } 
  else{
   return false;
}
}
</script>

Any idea?

You're not calling your ConfirmChk() function. You were also missing a quote at the end of the href, and had an extra quote after the onclick (maybe that was just an editing mistake when you added the onclick). It should be:

echo"<td><a href='/ADMIN/deletebooks.php?ID=".$row['ID']."' onclick='return ConfirmChk()'>Delete</a></td>";

You can also simplify the function. You don't need if/else, since confirm() returns true or false.

function ConfirmChk() {
    return confirm("Do you really want to delete this book?");
}

Looks to me like you forgot to close the href with a single quote.

echo"<td><a href='/ADMIN/deletebooks.php?ID=".$row['ID']."' onClick='return confirm('Do you really want to delete this book?')''>Delete</a></td>";