1

ファンシーボックスを使用してフォームを作成しようとしていますが、残念ながら入力要素と正しいマークアップが表示されていても、フォーム内の何かをクリックするとファンシーボックスが更新されます。クリックイベントバブルを無効にして、実際にテキスト入力ボックスに入ったり、派手なボックスを更新せずに選択オプションから選択したりできるようにするには、何が欠けていますか?

  $(document).ready(function() {
        var box = $("#show_mailing_list_signup");


        box.fancybox({
            'showCloseButton': true,
            'scrolling': 'no',
            'titleShow': false,
            'beforeLoad': function() {
                return !hideMailList();
            },
            'afterLoad': function() {

                $('#disableSignup').click(function() {
                    setCookie("hideSignup", true, 365);
                    $.fancybox.close();
                    return false;
                });

                $("#send_form").click(function() {

                    return false;
                });


            }
        }).click();
    });


<div id="show_mailing_list_signup">
        <form id="mailinglistForm" method="post">
            <h2>Header</h2>
            <label for="name">* Name </label>
            <p>
                <input name="fname" type="text" id="name" minlength="4" maxlength="15" />
            </p>
            <br />
            <label for="email">* Email </label>
            <p>
                <input name="email" type="text" id="email" />
            </p>
            <br />
            <label for="state">Pick your favorite school</label>
            <p>
                <select id="state">
                    <option>NY</option>
                    <option>IL</option>
                </select>
                <select id="city">
                    <option>Schenectedy</option>
                    <option>Fishkill</option>
                </select>
            </p>
            <p>
                <input id="schoolSearch" type="text"/>
            </p>

            <%--default to the most select school--%>
            <p style="margin-top: 20px;">
                <input value="Join Now" type="button" name="send_form" id="send_form" />
            </p>

        </form>
        <p class="details">blah</p>
        <a href="#" id="disableSignup">don't show again</a>
    </div>
4

1 に答える 1

5

これを行うと

var box = $("#show_mailing_list_signup");
    box.fancybox().click()

要素<div id="show_mailing_list_signup">(fancybox で開いたフォームを含む) は、fancybox のトリガーおよびターゲットclickになるため、そのコンテナー内にあるものはすべて、fancybox を何度もトリガーします。

セレクターを別のものに変更して、次のようにフォームをターゲットにします

var box = $(".fancybox");
    box.fancybox({
        // API options here
    }).click();

class="fancybox":あなたのようなものをターゲットにするには、まだhtml要素(通常はリンク)が必要ですform

<a class="fancybox" href="#show_mailing_list_signup"></a>
于 2013-10-22T01:29:44.597 に答える