我想按下提交按钮后显示一个div

时间:2015-10-23 05:00:36

标签: javascript html popup mailchimp

我需要一些帮助

您在下面的行中看到的“关闭模式”按钮在加载时隐藏,因为我想强制用户在访问内容之前写下他们的姓名和电子邮件。

<div class="mc-closeModal" data-action="close-mc-modal" data-dojo-attach-point="modalClose" style="">close</div>   

我现在要做的是在人们输入他们的姓名和电子邮件并按下“订阅”按钮后再次显示。

我在控制台中尝试了以下代码并且它可以正常工作。它提交详细信息并再次显示“关闭”按钮。

$(document).ready(function() {
$('iframe').contents().find('input.button').click() //this line targets the submit button "Subscribe"
$("#PopupSignupForm_0 > div.mc-modal > div.mc-closeModal").show() //this line makes the "close" button appear again
});

问题是,当我在网站上添加它时,它不起作用。

我想要的很简单

发生此事件时

    $('iframe').contents().find('input.button').click()

我想要执行

    $("#PopupSignupForm_0 > div.mc-modal > div.mc-closeModal").show()

1 个答案:

答案 0 :(得分:0)

您的代码只是一个接一个的两个声明。您实际上并未将任何内容绑定到click事件。如果您想使用jquery的点击,您可以执行以下操作:

$('iframe').contents().find('input.button').click(function() {
    $("#PopupSignupForm_0 > div.mc-modal > div.mc-closeModal").show()
});

但是你不知道用户是否真的填写了表格。相反,你可以 试试这个:

$('#content__formFields').submit(function() {
    var isValid = true;

    // Check if empty of not
    $(this).find('input[type!="hidden"]').each(function() {
        if (!$(this).val()) {
            isValid = false;
            //change the element's css here so user knows whats missing
        }
    });
    if (isValid)
        $("#PopupSignupForm_0 > div.mc-modal > div.mc-closeModal").show()
    return isValid
});
相关问题