每次点击都会刷新FancyBox

Rya*_*sch 1 html jquery fancybox fancybox-2

我正在尝试使用精美的盒子创建一个表单,即使它显示输入元素和正确的标记,但是单击表单中的任何内容都会导致fancybox刷新.我错过了什么来禁用点击事件气泡,以便您可以实际进入文本输入框或选择形式选择选项而不刷新框?

  $(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>
Run Code Online (Sandbox Code Playgroud)

JFK*_*JFK 5

当你这样做

var box = $("#show_mailing_list_signup");
    box.fancybox().click()
Run Code Online (Sandbox Code Playgroud)

元素<div id="show_mailing_list_signup">(包含你在fancybox中打开的形式)成为fancybox的触发器目标,所以你click在容器内的任何东西都会一遍又一遍地触发fancybox.

将选择器更改为其他内容以定位您的表单

var box = $(".fancybox");
    box.fancybox({
        // API options here
    }).click();
Run Code Online (Sandbox Code Playgroud)

注意:你仍然需要一个html元素(通常是一个链接)class="fancybox"来定位你的form喜欢:

<a class="fancybox" href="#show_mailing_list_signup"></a>
Run Code Online (Sandbox Code Playgroud)