2013-05-03 52 views
2

我正在開發一個使用phonegap的移動應用程序,並嘗試使用jquery將數據集成到sql數據庫,但表單似乎以奇怪的方式行事。 如果我將應用程序設置爲在應用程序啓動時直接導航到表單頁面,但它工作正常,但如果我嘗試從不同的初始頁面導航到表單頁面,表單將拒絕工作。 這個問題似乎是在第一個初始頁面上聲明jquery移動腳本。jQuery手機奇怪的形式行爲

如果任何人有任何想法發生了什麼,這將是偉大的,因爲我無法弄清楚!

HTML頁面爲帶鏈接

<!DOCTYPE HTML> 
<html lang="en-US"> 
<head>  
<title>jQuery form post</title> 
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> 

</head> 
<body> 
<div data-role="page" class="ui-responsive-panel" > 
<div data-role="header" > 
    <h1>New Submission</h1> 
</div>  

<div data-role="content"> 

<a href="comment_2.html" data-role = "button">New Submission</a> 

</div> 

</body> 
</html> 

HTML頁面的形式與

<!DOCTYPE HTML> 
<html lang="en-US"> 
<head>  
<title>jQuery form post</title> 
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> 
<script src="js/post.js"></script> 

</head> 
<body> 
<div data-role="page" class="ui-responsive-panel" > 
<div data-role="header" > 
    <h1>New Submission</h1> 
</div>  

<div data-role="content"> 

<div id="landmark-1" data-landmark-id="1"> 
<form id="comment"> 
    <label for="email"> 
     <b>Email</b> 
     <input type="email" id="email" name="email"> 
    </label> 

    <label for="comment"> 
     <b>Comment</b> 
     <textarea id="comment" name="comment" cols="30" rows="10"></textarea> 
    </label> 

    <input type="submit" value="Save"> 
</form> 
</div> 

</div> 

</body> 
</html> 

回答

0

jQuery手機甚至不包括你的post.js時,它不是第一頁。這是它的工作原理,第一頁上的所有內容都會被加載,然後它將通過AJAX注入data-role =「page」。這種行爲記錄在here

爲了解決這個問題,你有兩個選擇:

  1. 使用page change events之一來執行代碼。
  2. 將您的代碼移到data-role =「page」div中。
+0

謝謝! 通過將腳本移動到data-role =「page」div中來實現它。 – user2236497 2013-05-03 14:38:24

0

在comment.html頁頭部分只需添加:

<script src="js/post.js"></script> 

應工作?或者我錯過了什麼?

+0

剛剛嘗試並在comment.html頁面中更新它,但仍然無法正常工作! – user2236497 2013-05-03 13:41:42