jQuery手机奇怪的形式行为

问题描述:

我正在开发一个使用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> 

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

在comment.html页头部分只需添加:

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

应工作?或者我错过了什么?

+0

刚刚尝试并在comment.html页面中更新它,但仍然无法正常工作! – user2236497 2013-05-03 13:41:42