我正在使用jQuery mobile制作网络应用程序,但是我遇到了一些让插件协同工作的问题。我知道为什么会这样,但我无法解决它......
因此,在我的网络应用中,我选择了带有http://andymatthews.net autoComplete插件的项目。选择项目后,我将一些数据放在localStorage中。项目名称,ID等......
然后在选择项目后我有一些不同的表格,我使用jQuery form plugin提交。我使用PHP访问Mysql数据库,所以我通过jQuery表单插件从本地存储发布表单信息和一些变量。 (我用这个,因为我也通过一些表格上传图片..)
所以,问题是,jQuery表单插件需要放在$(document).ready(function(){})中,并且只有页面加载才生成数据,但每次选择new时我都会更改localStorage数据来自自动填充字段的项目。因此,每次从列表中选择另一个项目时,我需要重新启动应用程序,以将带有表单字段变量的localStorage变量传递给PHP。我已经尝试将jQuery表单插件放到$(“#page”)。live(“pageshow”,function(){})但插件无效...
以下是问题的示例:
顺便说一句,抱歉我的语言,但无论如何,谢谢你的任何建议......
$(document).ready(function() {
$('#innregulering_form').ajaxForm({
beforeSubmit: function(){
$.mobile.loading('show')},
data: ({project_id: localStorage.project_id,
project_prefix : localStorage.project_prefix}),
dataType: 'json',
failure: function(data) {
show_message('#innregulering_header', 'Can not save!', 'red')},
success: function(data) {
load_innregulering(data.apartament_id);
$.mobile.loading('hide');
$('#pop_innregulering_file_place').html('<b>File plased at:</b>' + data.file_patch + '</br><b>File name is: </b>' + data.file_name + '</br><b>File size is: </b>' + data.file_size + ' KB');
$('#tmp_pdf_file').val(data.file_name);
$("#wiev_innregulering_pdf_popup").popup( "open", {transition: "pop"})}
});
});
$("#select_project").live("pageshow", function(event, ui) {
if (localStorage.project_search){autocompleteData = JSON.parse(localStorage.project_search);} else {autocompleteData = '';}
$("#project_search").autocomplete({
target: $('#suggestions'),
source: autocompleteData,
link: '#project_home?',
minLength: 1,
matchFromStart: false,
callback: function(e) {
var $project = $(e.currentTarget); // access the selected item
var project_name = $project.data('autocomplete').label;
var project_prefix = $project.data('autocomplete').prefix;
var project_id = $project.data('autocomplete').project_id;
localStorage.setItem('project', project_name);
localStorage.setItem('project_prefix', project_prefix);
localStorage.setItem('project_id', project_id);}
});
});