Android的PhoneGap的+ + jQuery的验证 - 不点火 [英] Android + PhoneGap + jQuery Validate - not firing

查看:128
本文介绍了Android的PhoneGap的+ + jQuery的验证 - 不点火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery Mobile的使用jQuery验证。我有一个使用Ajax连载一旦所有网页均已完成张贴多种形式。

下一步按钮,从本地浏览器进行访问时,下面适用于iOS和Android。当我用打包和的PhoneGap在Android上运行,验证不火。其他一切工作正常。

如果我删除了有效的()状态,按钮按预期工作。因此,它必须与我在如何使用jQuery验证的问题。

我已经试过各种方式转移事物的秩序。我试过:

 如果(!$(#infofm)。有效的()){

 如果($(#infofm)。有效的()){

总是相同的结果 - 工作在本地的浏览器,但不是的PhoneGap之后。我一直在挣扎与此很长一段时间。下面是相关的code。任何帮助将非常AP preciated。谢谢!

  $(函数(){
    $('A#NXT1')。绑定('点击',功能(事件,UI){
        infoval();
    });功能infoval(){
    。VAR isvalidate = $(#infofm),有效();
    如果(isvalidate){
        $ .mobile.changePage('#towertop',{过渡:slidefade'});
    }其他{
        警报(请过程使用前在此页面上的所有字段填写);
    }
};$(文件)。就绪(函数(){
$(#infofm)来验证。({errorPlacement:功能(错误,元素){}}); });

 < A HREF =ID =NXT1数据iconpos =自下而上的数据主题=数据图标=箭头-R>接下来步骤< / A>


解决方案

当(在我的情况在iOS)捆绑成一个PhoneGap的应用我的JavaScript code没有被调用。我建有多个屏幕和按钮被隐藏或显示的根据用户交互的web应用程序。

在使用的iOS模拟器X $ C $捆绑C,你可以看到在Safari中生成的Web应用程序的源$ C ​​$ C(以下简称开发菜单下,开发工具必须在Safari浏览器$ P $启用pferences)。在源$ C ​​$ C,我注意到,我所有的应用程序的HTML页面被合并成一个,其中包括唯一的JavaScript是从第一页(默认的index.html) - 页面中的所有其他元素从文件中被删除。所以我改变了

  $(文件)。就绪(函数(){
       ...
    });

 的$(document)。在('pageinit',函数(){
       ...
    });

(Sparky的感谢,上面你的答案),并添加了所有jQuery的JS code从下面的页面转换成的index.html。作为一个例子,我添加了以下行隐藏在页面的一个DIV:

  $(#cancelButtonDiv),隐藏();

目前正在执行的code和我的按钮指定的方法被正确调用。

I'm using jQuery Mobile with jQuery Validate. I have multiple forms that post with ajax serialize once all pages have been completed.

The 'next' button below works on iOS and Android when accessed from the native browser. When I package with PhoneGap and run on Android, the validation does not fire. Everything else works fine.

If I remove the valid() condition, the button works as expected. So it must be an issue with how I'm using jQuery Validate.

I've tried shifting the order of things in various ways. I've tried:

if (!$("#infofm").valid()) {

And

if($("#infofm").valid()) {

Always the same result - works in native browsers, but not after PhoneGap. I've been struggling with this for a long time now. Here's the relevant code. Any help would be very much appreciated. Thanks!

$(function(){ 
    $('a#nxt1').bind('click', function(event, ui) {
        infoval();
    });

function infoval(){
    var isvalidate=$("#infofm").valid();
    if(isvalidate) {
        $.mobile.changePage('#towertop', {transition: 'slidefade'});
    } else {
        alert("Please fill in all fields on this page before proceding");
    }
};

$(document).ready( function(){ 
$("#infofm").validate({ errorPlacement: function(error, element) {} }); });

AND

<a href="" id="nxt1" data-iconpos="bottom" data-theme="a" data-icon="arrow-r">Next Step</a>

解决方案

My javaScript code was not being called when bundled into a phonegap app (on iOS in my case). I built a web app with multiple screens and buttons that are hidden or displayed depending on user interaction.

When using the iOS simulator bundled with XCode you can see the sourcecode of the generated web app in safari (under the "Develop" menu, developer tools have to be enabled in Safari preferences). In the source code I noticed that the all my apps html pages are merged into one and the only javascript included is from the first page (default index.html) - all other elements within the page were removed from the file. So I changed

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

to

    $(document).on('pageinit', function(){
       ...
    });

(thanks Sparky, for your answer above) and added all the jquery js code from the following pages into index.html. As an example I added the following line to hide a div on one of the pages:

    $("#cancelButtonDiv").hide();

The code is now being executed and the methods specified on my buttons are being called properly.

这篇关于Android的PhoneGap的+ + jQuery的验证 - 不点火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆