2015-05-02 59 views
1

當我使用這個腳本如何使用javascript加載表單?

<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

使用$(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> 
+0

我需要js代碼。因爲提交後我想顯示隱藏的div。 – Nivin

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

使用上面的代碼。這將工作。

相關問題