2016-03-01 68 views
-1

我已经使用此函数进行表单验证。我没有使用这个功能如何在文档就绪功能下使用回调函数

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

它的工作很好。现在我想在此下添加我的代码

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

我该怎么做。谢谢。

function myFunction() { 
     var a = document.getElementById("num").value; 
     var b = document.getElementById("num2").value; 
     var msg = ""; 

     if(a==""){ 
      msg+="Please Fill this field.\n"; 
      num.className = "color"; 
     } 

     if(b==""){ 
      msg+="Please Fill this field.\n"; 
      num2.className = "color"; 
     } 
     if(msg=="") { 
      return true; 
     } 
     else { 
      document.getElementById("result").innerHTML="Please fill the user name"; 
      document.getElementById("result2").innerHTML="Please Put your E-mail"; 
      return false; 
     } 
    } 
+0

'$(文件)。就绪(myFunction的)'应该为你 –

回答

0
$(document).ready(function(){ myFunction(); }); 
+0

对不起,先生的工作。它不工作:( – Musarrof

相关问题