找到你要的答案

Q:How to load a form using javascript?

Q:如何使用JavaScript加载形式?

When I use this script

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

the form will load normally. But the below script didn't load form. I think problem related to 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>

How to fix this problem........

当我使用这个脚本

<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>

如何解决这一问题的........

answer1: 回答1:
<form id="mktoForm_1740"></form>
<script>MktoForms2.loadForm("//app-example.com", "517-ITT-285", 1740, function(form){
    form.onSuccess(function(values, followUpUrl){
        form.getFormElem().hide();
        document.getElementById('confirmform').style.visibility = 'visible';
        return false;
    });
});</script>

Use above code. this will work.

<form id="mktoForm_1740"></form>
<script>MktoForms2.loadForm("//app-example.com", "517-ITT-285", 1740, function(form){
    form.onSuccess(function(values, followUpUrl){
        form.getFormElem().hide();
        document.getElementById('confirmform').style.visibility = 'visible';
        return false;
    });
});</script>

使用以上代码。这将工作。

answer2: 回答2:

use $(document).ready(function(){});

try this

<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>

使用$(document)。准备(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>
javascript  jquery  html