1

すべて。

これは比較的単純なことですが、JavaScriptの経験が浅いことがわかります。背景は、同じページで別々のモーダルでSimpleModalを使用しようとしていることです。この種のことは以前に説明されていますが(http://code.google.com/p/simplemodal/issues/detail?id=32)、this.idを十分に理解しておらず、コードも理解できません。働く。

私の用語はここでも正しいとは思いませんが、セレクターは私のリンクのアイデアを適切に取得しておらず、「#osx_」文字列で解析していません。アラートを使用した後、これに気づきました(文字通り数時間後)。

$('a.osx').click(function () {
$('#osx_' + this.id).modal();
});

HTMLが正しく設定されていることはわかっています。両方の場所に「#osx_newsletter」をハードコーディングすると、問題なく機能します。それは明らかに私が必要とする動的IDを殺します。

これがコードです。誰かが私がここで間違っていることを教えてもらえますか?よろしくお願います!ありがとう!

/*
 * SimpleModal OSX Style Modal Dialog
 * http://simplemodal.com
 *
 * Copyright (c) 2013 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 */

jQuery(function ($) {
    var OSX = {
        container: null,
        init: function () {
            $("a.osx").click(function (e) {
                e.preventDefault(); 
alert('#osx_'+$(this).attr('id'));
                $('#osx_' + 'donate').modal({
                    overlayId: 'osx-overlay',
                    containerId: 'osx-container',
                    closeHTML: null,
                    minHeight: 80,
                    opacity: 65, 
                    position: ['0',],
                    overlayClose: true,
                    onOpen: OSX.open,
                    onClose: OSX.close
                });
            });
        },
        open: function (d) {
            var self = this;
            self.container = d.container[0];
            d.overlay.fadeIn('slow', function () {
                $('#osx_' + 'donate', self.container).show();
                var title = $("#osx-modal-title", self.container);
                title.show();
                d.container.slideDown('slow', function () {
                    setTimeout(function () {
                        var h = $("#osx-modal-data", self.container).height()
                            + title.height()
                            + 20; // padding
                        d.container.animate(
                            {height: h}, 
                            200,
                            function () {
                                $("div.close", self.container).show();
                                $("#osx-modal-data", self.container).show();
                            }
                        );
                    }, 300);
                });
            })
        },
        close: function (d) {
            var self = this; // this = SimpleModal object
            d.container.animate(
                {top:"-" + (d.container.height() + 20)},
                500,
                function () {
                    self.close(); // or $.modal.close();
                }
            );
        }
    };

    OSX.init();

});
4

1 に答える 1

0

この方法を試すことができます:

$('a.osx').click(function () {
    $('[id="osx_' + this.id+'"]').modal();
});
于 2013-01-30T10:30:57.657 に答える