JavaScript onClick href

时间:2011-03-14 11:13:43

标签: php javascript

使用<a>标签,我可以像:

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

以及如何将该代码应用于按钮:

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

4 个答案:

答案 0 :(得分:2)

如果您想通过稍微改变来实现目标,请尝试以下方法:

<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" />

答案 1 :(得分:2)

<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;

}

答案 2 :(得分:0)

按钮不是超链接。

要使按钮导航到其他页面,您可以在location = 'URL';处理程序中编写click

答案 3 :(得分:0)

<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>

您还可以使用onsubmit标记的<form>