私は次のことをしたい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>
アップデート:
<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>