0

送信ボタンのあるフォームをロードするjQueryモーダルウィンドウがあります。フォームをクリアしてポップアップを閉じる「キャンセル」リンクを追加したいと思います。

新しい ASP.NET MVC4 デフォルト テンプレートに付属するコードを使用しています。これを機能させるためのスクリプトを探しています。

これは、ダイアログの保存と表示に使用される現在のコードです。

$(function () {
    // Cache for dialogs
    var dialogs = {};
    var loadAndShowDialog = function (id, link, url) {
        var separator = url.indexOf('?') >= 0 ? '&' : '?';

        // Save an empty jQuery in our cache for now.
        dialogs[id] = $();

        // Load the dialog with the content=1 QueryString in order to get a PartialView
        $.get(url + separator + 'content=1')
            .done(function (content) {
                dialogs[id] = $('<div class="modal-popup">' + content + '</div>')
                    .hide() // Hide the dialog for now so we prevent flicker
                    .appendTo(document.body)
                    .filter('div') // Filter for the div tag only, script tags could surface
                    .dialog({ // Create the jQuery UI dialog
                        title: link.data('dialog-title') || 'Inloggen',
                        modal: true,
                        resizable: false,
                        draggable: false,
                        width: link.data('dialog-width') || 370,
                        beforeClose: function () { resetForm($(this).find('form')); }
                    })
                    .find('form') // Attach logic on forms
                        .submit(formSubmitHandler)
                        .find('a.close-dialog').click(function (id) {
                            //dialog close logic here
                        }).end();

            });
    };

    var links = ['.loginLink'];

    $.each(links, function (i, id) {
        $(id).click(function (e) {
            var link = $(this),
                url = link.attr('href');

            if (!dialogs[id]) {
                loadAndShowDialog(id, link, url);
            } else {
                dialogs[id].dialog('open');
            }

            // Prevent the normal behavior since we use a dialog
            e.preventDefault();
        });
    });
4

1 に答える 1

0

buttons:{Continue: function() { $(this).dialog('close');} }

ダイアログ属性内で上記のコードを試してください。

于 2012-04-17T11:07:16.670 に答える