我正在使用
jquery validate.js在我的jquery移动应用程序中验证我的联系表单.
当我通过url或页面刷新加载页面时,验证似乎完美无缺.
但是当我从另一个刷新的页面链接返回联系表单时,验证将停止工作.
当我通过url或页面刷新加载页面时,验证似乎完美无缺.
但是当我从另一个刷新的页面链接返回联系表单时,验证将停止工作.
1)在jquery mobile js之前包含contact.js.
2)data-ajax =“false”;
3)使用bind
$(document).bind("mobileinit",function(){ $.extend( $.mobile,{ ajaxEnabled: false }); });
4)refresh form page with jQuery Mobile
5)使用window.onload
window.onload = function() { if(!window.location.hash) { window.location = window.location + '#loaded'; window.location.reload(); } }
5)Jquery-Mobile: How to reload/refresh the internal page
6)One time page refresh after first page load
Javascript working only on page refresh in jQuery mobile
但这些都不起作用.我需要做的是在导航到它时刷新页面一次.
这是我与jquery mobile的联系表单代码.
<form method="post" action="" id="Feedback" name="Feedback"> <input type="text" name="user_name" data-role="none" id="name" value="" placeholder= "Your name*" /> <br /> <input class="email" required="true" type="text" name="user_email" data-role="none" id="email" value="" placeholder="Your Email*" /> <br /> <textarea cols="70" rows="12" class="required" name="user_message" id="c_message" data-role="none" placeholder="Your message*"> </textarea> <br /> <input type="submit" value="Send" data-mini="true" data-role="none" data-inline="true" class="green_like" id="send" /> </form>
这是JS代码,位于“联系我们”表格中.
$(document).bind("pageinit",function(){ $("#Feedback").validate({ submitHandler : function() { $.ajax({ type:'POST',url :'/some/url',data: $('#Feedback').serialize(),success: function(resp) { if(resp==1) { $("#success_post_contact").html('<label style="color:green;margin-left: 6px;" >Thank you for contacting us.</label>'); } } });//end of ajax }//end of submit handler });//end of validate });//end of document.bind