PhoneGap& jQuery Mobile:脚本不加载 [英] PhoneGap & jQuery Mobile: Script does not load

查看:104
本文介绍了PhoneGap& jQuery Mobile:脚本不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了我的一天在以下问题面前。我试图得到PhoneGap和jQuery-mobile运行。应用程序启动,但如果我提交表单,他再次加载相同的网站,忽略在form.js中的一切(见下面的html代码)。
我有这个html代码:

I spend my day in front of the following problem. I tried to get PhoneGap and jQuery-mobile running. The app starts but, if I submit the form he loads the same site again, ignoring everything in the form.js (see below the html-code). I have this html-Code:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.2.0.min.css" />
    <script type="text/javascript" src="js/jQuery/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/jQuery/jquery-migrate-1.0.0.js"></script>
    <script type="text/javascript" src="cordova-2.4.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/form.js"></script>
    <script type="text/javascript" src="js/jQuery.mobile/jquery.mobile-1.2.0.min.js"></script>
    <title>SecureBook</title>
</head>
<body onload="app.initialize();">
    <div data-role="page">
        <div data-role="header">
            <h1>Welcome</h1>
        </div>
        <div data-role="content">
            <form id="userdata">
                <input type="text" id="username" placeholder="Username"  autofocus>
                <input type="password" id="password" placeholder="Passoword">
                <input type="submit" value="Anmelden" data-icon="forward" data-theme="b">
            </form>
        </div>
        <script>
            gotLoaded();
            console.log("in HTML");
        </script>
    </div>
</body>

t加载form.js,因为他没有调用函数gotLoaded()和console.logging任何东西。 form.js看起来像这样:

It seems like he doesn't load the form.js as he isn't calling the function gotLoaded() nor console.logging anything. The form.js looks as like that:

function gotLoaded(){
console.log("loaded form");
};
$('#userdata').submit(function(event){
    console.log("transmitted form");
    event.preventDefault();
    var user = $('#username').val();
    var password = $('#password').val();
    $.mobile.changePage("sites/contacts.html",{
        transition: "none"
    });
});

然而,他将所有其他脚本加载到js文件夹之外,从form.js。至少不是在我的Android手机上,在浏览器他显示我的日志我的东西。我希望你能帮助我。
非常感谢,
stiller_leser

He does however load all the other scripts out of the js-folder, but isn't executing anything from the form.js. At least not on my Android-phone, in the Browser he is showing me the things I log. I hope you might be able to help me. Thanks a lot, stiller_leser

只是看到他不是日志(传输形式)。

P.S. Just saw that he isn't logging ("transmitted form") either.

推荐答案

适用于我,如下所示。不知道为什么。似乎在最后添加我的表单脚本确保所有的jQuery-Stuff加载。这是最后的代码。

works for me as shown below. Got no idea why though. Seems like adding my form script at the end makes sure that all jQuery-Stuff is loaded. Here's the final code.

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.2.0.min.css" />

    <script type="text/javascript" src="cordova-2.4.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/jQuery/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/jQuery/jquery-migrate-1.0.0.js"></script>  
    <script type="text/javascript" src="js/jQuery.mobile/jquery.mobile-1.2.0.min.js"></script>       
    <title>SecureBook</title>
</head>
<body onload="app.initialize();">
    <div data-role="page">
        <div data-role="header">
            <h1>Welcome</h1>
        </div>
        <div data-role="content">
            <form id="userdata" onsubmit="gotLoaded();">
                <input type="text" id="username" placeholder="Username"  autofocus>
                <input type="password" id="password" placeholder="Passoword">
                <input type="submit" value="Anmelden" data-icon="forward" data-theme="b">
            </form>
        </div>
        <script>
            //WORKS
            console.log("in HTML");
            //JQUERY works here
            console.log($('title').html());
        </script>
    </div>

<!-- Put customs scripts here as it seems, that jQuery loads to slow in the head and scripts already run -->
<script type="text/javascript" src="js/form.js"></script>
</body>

这篇关于PhoneGap&amp; jQuery Mobile:脚本不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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