ブートストラップでブログを作成しており、カテゴリを送信するフォームがあります:
<form action="categories.php" id="category-form" class="form-horizontal" role="form" method="post">
<div class="form-group">
<label for="category" class="col-sm-2 control-label">Category</label>
<div class="col-sm-10">
<input type="text" name="category" class="form-control" id="category" placeholder="Category">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" name="submit" id="btn-submit" class="btn btn-primary" value="Add Category">
</div>
</div>
</form>
フォームボタン「カテゴリを追加」を押すとダイアログが表示されますが、数秒後にすぐに送信され、「はい」または「いいえ」ボタンをクリックせずにダイアログが消え、ウェブを検索するといくつかの解決策が見つかりましたが、機能しません私のため。Alertify JS に使用するコードは次のとおりです。
$("#btn-submit").on("click", function(){
alertify.confirm("This is an alert dialog?", function(e){
if (e) {
alertify.success("Category was saved.")
} else {
alertify.error("Category not saved.");
}
});
return false;
});
私も試しevent.preventDefault();
ます:
$("#btn-submit").on("click", function(event){
event.preventDefault();
alertify.confirm("This is an alert dialog?", function(e){
if (e) {
$("#category-form").submit();
alertify.success("Category was saved.")
return true;
} else {
alertify.error("Category not saved.");
return false;
}
});
});
しかし、うまくいきません。助けてください...ありがとう。