我有2個按鈕,我要做到以下幾點但目前還不做任何事情:2按鈕不進行任何形式的功能
啓用按鈕:
- 按鈕的onclick將訪問
enableHandler()
功能,如果用戶 確認確認,則導航用戶到penaltymarks.php
頁面。
禁用按鈕:
- 按鈕的onclick將訪問
disableHandler()
功能,如果用戶 確認確認,然後將用戶導航到completes.php
頁面和AJAX將導航到completesession.php
頁的背景。
如何讓我的按鈕執行上述操作,因爲目前我的代碼沒有任何問題。我是否需要<form>
標籤,因爲我沒有在我的代碼中包含表單標籤。
<script type="text/javascript">
$(function() {
enableHandler() {
if (confirm("Are you sure you wish to enable Penalty Marks?" + "\n" + "(You cannot change your option once you have confirmed)" + "\n"))
{
$.ajax({
url: "penaltymarks.php",
async: false,
type: "POST"
});
return true;
}
};
});
$(function() {
disableHandler() {
if (confirm("Are you sure you wish to disable Penalty Marks?" + "\n" + "(You cannot change your option once you have confirmed)" + "\n"))
{
$.ajax({
url: "sessioncomplete.php",
async: false,
type: "POST"
});
return true;
}
};
});
</script>
UPDATE:
<table>
<tr>
<td><input type="button" id="enablePenalty" value="Enable Penalty Marks"/></td>
<td><input type="button" id="disablePenalty" value="Do Not Enable Penalty Marks"/></td>
</tr>
</table>
<script type="text/javascript">
$('#enablePenalty').click(function() {
if (confirm("Are you sure you wish to enable Penalty Marks?" + "\n" + "(You cannot change your option once you have confirmed)" + "\n"))
{
window.location = "penaltymarks.php",
return true;
}
});
$('#disablePenalty').click(function() {
if (confirm("Are you sure you wish to disable Penalty Marks?" + "\n" + "(You cannot change your option once you have confirmed)" + "\n"))
{
$.ajax({
url: "sessioncomplete.php",
async: false,
type: "POST"
});
window.location = "complete.php",
return true;
}
});
</script>
你得到的錯誤是什麼?檢查您的控制檯 – Ankush