[英]JavaScript onClick href
使用<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>
以及如何將該代碼應用於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;
}
按鈕不是超鏈接。
要使按鈕導航到其他頁面,您可以輸入location = 'URL';
在click
處理程序中。
<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>
您也可以使用<form>
標記的onsubmit
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.