简体   繁体   中英

JavaScript onClick href

with the use of <a> tag, i can put like:

<a href="include/sendemail.php?id_user=<?= $_GET['id_user'];?>" onclick="return confirm('Are you sure want to send an email?');" >Send Email</a>

and how do apply that code to button :

<input type="button" onclick="return confirm('Are you sure want to send an email?');"  value="Send Email" >

如果您只需要一点点改动就可以实现自己的目标,请尝试以下操作:

<input type="button" onclick="if(confirm('Are you sure want to send an email?')) { document.location.href = 'include/sendemail.php?id_user='; } " value="Send Email" />
<input type="button" onclick="return myFunc();"  value="Send Email" >

<script>

function myFunc()
{
 var flag = confirm('Are you sure want to send an email?');
 if(flag)
  document.location.href = "include/sendemail.php?id_user=<?= $_GET['id_user'];?>" ;
 else
   return false;

}

Buttons are not hyperlinks.

To make a button navigate to a different page, you can write location = 'URL'; in the click handler.

<form action="include/sendemail.php" method="GET">
<input type="hidden" name="id_user" value="<?php echo intval($_GET['id_user']); ?>" />
<input type="button" onclick="return confirm('Are you sure want to send an email?');"  value="Send Email" />
</form>

You could also use onsubmit of the <form> tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM