我正在进行表单提交,并且我正在显示一个确认框,询问用户是否确实要继续。但即使用户点击取消,表单仍然会被提交。
<form onsubmit="return confirm('If you enter the incorrect number, the search will still be conducted and charge you for the cost of the search. do you want to continue?.')" action="http:example.com/" id="customersearch" name="customersearch" role="form" method="post" accept-charset="utf-8" novalidate="novalidate">
我该如何避免这种情况?有人可以告诉我如何在用户点击取消时停止提交表单吗?
答案 0 :(得分:3)
答案 1 :(得分:0)
以下是工作代码段,您的代码也正常工作:
@Override public Dialog onCreateDialog(Bundle savedInstanceState) {
final BottomSheetDialog bottomSheetDialog =
(BottomSheetDialog) super.onCreateDialog(savedInstanceState);
bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override public void onShow(DialogInterface dialog) {
FrameLayout bottomSheet =
bottomSheetDialog.findViewById(android.support.design.R.id.design_bottom_sheet);
if (null != bottomSheet) {
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setHideable(false);
}
}
});
return bottomSheetDialog;
}