如何使用javascript加载表单?

时间:2015-05-02 08:59:53

标签: javascript jquery html

当我使用这个脚本时

<form id="mktoForm_1740"></form>
<script>MktoForms2.loadForm("//app-e.example.com", "517-ITT-285", 1740);</script>

表单将正常加载。但是下面的脚本没有加载表单。我认为问题与javascript有关。

<script>MktoForms2.loadForm("//app-example.com", "517-ITT-285", 1740, function(form){
    //Add an onSuccess handler
    form.onSuccess(function(values, followUpUrl){
        //get the form's jQuery element and hide it
        form.getFormElem().hide();
        document.getElementById('confirmform').style.visibility = 'visible';
        //return false to prevent the submission handler from taking the lead to the follow up url.
        return false;
    });
    });
</script>
<div id="confirmform" style="visibility:hidden;margin-top: 35px;"><p><strong>Thank you for registering. You will receive a confirmation by email in a minute.</strong></p></div>

如何解决这个问题........

1 个答案:

答案 0 :(得分:1)

使用$(document).ready(function(){});

试试这个

<script>
    $(document).ready(function() {
        MktoForms2.loadForm("//app-example.com", "517-ITT-285", 1740, function(form) {
            //Add an onSuccess handler
            form.onSuccess(function(values, followUpUrl) {
                //get the form's jQuery element and hide it
                form.getFormElem().hide();
                document.getElementById('confirmform').style.visibility = 'visible';
                //return false to prevent the submission handler from taking the lead to the follow up url.
                return false;
            });
        });
    });
</script>
<div id="confirmform" style="visibility:hidden;margin-top: 35px;">
    <p><strong>Thank you for registering. You will receive a confirmation by email in a minute.</strong></p>
</div>