0

我是 jquery mobile 的新手,我使用 jquery mobile 和 phoneGap 以及 localstorage Html 开发了一个移动应用程序,我想在 page.html 中保存一个输入值,然后我将使用 localstorage.getitem 检索这个值并在 URL 中使用, 我的问题当我添加这条线时 value=localStorage.getItem('myStorage');我无法连接到我的应用程序并且我收到了这个错误:

表达式 '$.mobile' [undefined] 的结果不是对象。在文件:///android_asset/www/js/application.js:258

这是我保存输入值 application.js 的应用程序

function setMessage() {
    var firstName=document.getElementById('addresseip');
    alert("Hello " + firstName.value + ", hope you like JavaScript functions!")

                    localStorage.setItem('myStorage', firstName.value);

}

这是我在同一页面 .js 中对这个值的调用,输入值是 param.html,对这个值的调用在 index.html 中:

function showUser(){
 value=localStorage.getItem('myStorage');
val1 = document.getElementById("name").value;
val2 = document.getElementById("pass").value;

if (val1=="")
  {
   showdialog("Verifiez login et mot de passe","Erreur");
  } 
  else{
     alert("test"+value);    
  $.mobile.showPageLoadingMsg();    
   var geturl;
  geturl = $.ajax({  

   url:"https://"+value+":80/B/authenticate",  
   //url:"https://10.0.2.2:80/B/authenticate",  
   dataType:"json",
   timeout:10000000,  
   cache:false,
   type:'GET',
   beforeSend : function(req) {
             req.setRequestHeader('Authorization', 
                   make_base_auth (val1, val2));
        },
   error:function(XMLHttpRequest,textStatus, errorThrown) { 
   $.mobile.hidePageLoadingMsg();
   showdialog("Verifiez login et mot de passe","Erreur"); 
   },   
   success:function(results) { 
   if(results==true){

    $.mobile.changePage("bienvenu.html","fade");
    $.mobile.hidePageLoadingMsg();  
   }

我的错误是一行 $.mobile.showPageLoadingMsg();

你能帮我吗,谢谢

4

2 回答 2

0

既然$.mobileundefined,我猜jquery移动库没有加载。在调用之前检查您是否已加载 jquery 和 jquery mobile showUser()

于 2012-06-11T02:46:27.043 回答
0

除了加载 jQuery,您还应该包括 jQM。还要确保在它之后包含使用 jQM 的代码。

<script src="//code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script src="yourscripts.js"></script>

或者

<script src="//code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script>
    /* Your code here */
</script>
于 2012-06-11T14:04:09.367 回答