Php 通过jQuery警报确认提交触发表单
我会尽我所能说清楚的 基本上,我的表单允许您从选择框中删除玩家 当用户按下“删除”按钮时,会出现一个确认框,告诉用户如果继续,他们将无法取回该数据。预期的行为是,当用户按下“OK”时,删除脚本将运行并删除播放器。如果您删除确认框并允许提交按钮的默认行为,则它的工作方式与我所希望的一样。如果我能添加中间步骤,我会更加专业 以下是我的相关HTML代码:Php 通过jQuery警报确认提交触发表单,php,jquery,html,forms,preventdefault,Php,Jquery,Html,Forms,Preventdefault,我会尽我所能说清楚的 基本上,我的表单允许您从选择框中删除玩家 当用户按下“删除”按钮时,会出现一个确认框,告诉用户如果继续,他们将无法取回该数据。预期的行为是,当用户按下“OK”时,删除脚本将运行并删除播放器。如果您删除确认框并允许提交按钮的默认行为,则它的工作方式与我所希望的一样。如果我能添加中间步骤,我会更加专业 以下是我的相关HTML代码: <form id="player-list" action="edit-player.php?playerid=22" method="po
<form id="player-list" action="edit-player.php?playerid=22" method="post">
<div id="player-box" class="row">
<div class="small-12 medium-offset-4 medium-4 columns">
<label>Team
<select id="all-players" name="team-division">
<?php
$SQL = "SELECT
ID,
firstName,
lastName
FROM
players";
$playerResult = mysqli_query($link, $SQL);
$counter = 1;
while($row = mysqli_fetch_array($playerResult)) {
echo '<option value="player-' . $row['ID'] . '">' . substr($row['firstName'], 0, 1) . " " . $row['lastName'] . '</option>';
}
?>
</select>
<br />
</label>
</div>
</div>
<div class="row">
<div class="small-12 medium-2 medium-offset-4 columns ">
<a id="player-selection" class="button expanded radius success">Submit</a>
</div>
<div class="small-12 medium-2 columns end">
<input type="submit" id="player-deletion" class="button expanded radius alert" name="delete-player" value="Delete" />
</div>
</div>
</form>
这个代码不起作用。我知道我必须阻止默认操作发生,但在用户单击“确定”后,我想从确认按钮重新启动提交功能
这可能吗
任何帮助都将不胜感激
谢谢。如果用户在确认对话框中按“取消”,则只需返回false。否则它将通过默认流
$("#player-deletion").on('click', function(e) {
if (!confirm("This record will be permanentely deleted. Is that OK?")) {
return false;
}
});
您只需返回
confirm
返回的内容即可returnfalse
与调用e.preventDefault()
和e.stopPropagation()
相同。停止事件传播将取消提交
$("#player-deletion").click(function(e) {
return confirm("This record will be permanentely deleted. Is that OK?");
});
将if语句更改为
if (confirm("This record will be permanentely deleted. Is that OK?") == true) {
//submit regardless
} else {
e.preventDefault();//do something other here
}
“我想从确认按钮重新设置提交功能。”为什么?如果你不阻止默认操作,它可能会被触发。很抱歉,过了一段时间才回复你。一直忙于工作和其他事情。你的解决方案很好用。谢谢
if (confirm("This record will be permanentely deleted. Is that OK?") == true) {
//submit regardless
} else {
e.preventDefault();//do something other here
}