jQueryダイアログ確認、フォームポストの確認
-
05-10-2019 - |
質問
フォームを送信する前に、JQueryのダイアログ確認を表示しようとしています。しかし、フォームが送信された場合にのみポップアップを作成することはできません。これはコードです。
$(function remove() {
$("#dialog-confirm").dialog({
resizable: false,
height:200,
modal: true,
buttons: {
'Delete campaign': function() {
return true ;
$(this).dialog('close');
},
Cancel: function() {
return false;
$(this).dialog('close');
}
}
});
});
ダイアログ確認コンテンツ
<div id="dialog-confirm" title="Delete ?" style="display:none;">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
フォーム送信コンテンツ
<form style="display: inline;" action="remove.php" method="post"" onsubmit="return remove()">
解決
関数 remove
に配置しないでください $(...);
, 、 なので $(function(){})
ドキュメントがロードされたときに自動的に実行されるものは、ルートで明確に定義する関数を移動するだけです。また、インラインコールバックを使用することをお勧めします。設定します id
フォームで、代わりに次のように使用します。
すなわち
function remove() {
...
}
$(function(){
$('#formid').submit(remove);
// normal initializing code here, which is executed when document is ready
})
または、コールバックを直接定義することもできます。
$(function(){
$('#formid').submit(function(){
// same code as in remove function above
});
// normal initializing code here, which is executed when document is ready
})
所属していません StackOverflow