我确认了这一点:
<script type="text/javascript">
function ConfirmDelete() {
if (confirm("Are you sure you want to delete?")) {
return true;
}
else {
return false;
}
}
</script>
然后我有Laravel表格:
{!! Form::open(['action' => ['Test\\TestController@destroy', $thread->id], 'method' => 'delete', 'onsubmit' => 'ConfirmDelete()']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
我收到了消息,如果我按下确定,则线程会被删除,但这也会在取消时发生。如果我按下取消,我该怎么做才能发生任何事情?
答案 0 :(得分:1)
您可以进一步整理您的javascript
$1$3\r\n$1$2
此外,您需要确保在提交时返回功能的响应,例如
<script type="text/javascript">
function ConfirmDelete() {
return confirm("Are you sure you want to delete?");
}
</script>
答案 1 :(得分:0)
更改为:
<button (click)="save()" [disabled]="!myForm.form.valid">Click 2</button>
答案 2 :(得分:0)
您需要在函数调用之前添加return语句。
更改以下代码
'onsubmit' => 'ConfirmDelete()'
到
'onsubmit' => 'return ConfirmDelete()'
如果你愿意,你也可以内联它;)
'onsubmit' => 'return confirm("Are you sure you want to delete?")'
在onclick
事件处理程序the return value of an event handler determines whether or not the default browser behavior should take place as well中调用JavaScript函数时。
这就是为什么即使您从确认对话框中按Cancel
它也会被删除。