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