0

フォームを送信する前に、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()">
4

1 に答える 1

1

関数は、ドキュメントがロードされたときに自動的に実行されるもののように、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
})   
于 2010-05-29T16:23:27.457 に答える