Jquery mobile 如何使用jquery mobile从secondpage.html调用的函数更新index.html
我正在使用新的cordova.js、jquery mobile和我自己的custom.js构建一个phonegap应用程序 在主页index.html上是一个值列表,最初为空 当您单击index.html页面上的设置链接时,将转到secondpage.html,在其中输入一些值。当您单击secondpage.html上的submit按钮时,我会在my custom.js中调用一个名为updatevalues()的函数,该函数用于更新index.html上列表中的值。这种情况不会发生。帮我理解为什么?下面是index.html、secondpage.html和custom.js文件 ----------------index.htmlJquery mobile 如何使用jquery mobile从secondpage.html调用的函数更新index.html,jquery-mobile,cordova,Jquery Mobile,Cordova,我正在使用新的cordova.js、jquery mobile和我自己的custom.js构建一个phonegap应用程序 在主页index.html上是一个值列表,最初为空 当您单击index.html页面上的设置链接时,将转到secondpage.html,在其中输入一些值。当您单击secondpage.html上的submit按钮时,我会在my custom.js中调用一个名为updatevalues()的函数,该函数用于更新index.html上列表中的值。这种情况不会发生。帮我理解为什
音差
主页
主菜单
$(document).delegate(“#mainpage”,“pageinit”,function()){
警报('jQuery Mobile即将创建ID为“mainpage”的页面!');
updateValue();
});
----------------------secondpage.html
安装程序
安装程序
您的起始配置文件
*=必需
输入您的年龄*
重量(磅)*
请填写所有必填字段
您的值已设置。
$(文档).ready(函数(){
//分配全局变量
//hdrMainVar=$('hdrMain');
$('.maindivs').show();
$('.requireddivs').hide();
$('.updateddivs').hide();
});
-----------------------------custom.js
函数updatevalues()
{
警报(“检查值”);
var yourageVar=window.localStorage.getItem(“yourageLocal”);
var-weightVar=window.localStorage.getItem(“weightLocal”);
警报(“yourageVar=“+yourageVar”);
警报(“weightVar=“+weightVar”);
如果(!yourageVar | |!weightVar)
{
$(“#contentlist”).empty();//清空我们在html中放置的列表元素
//使用phonegap设备api中的数据重新填充列表
$(“#内容列表”)。追加(“您的年龄:0 ”;
$(“#内容列表”)。附加(您的体重:0 ”;
$(“#contentlist”).listview('refresh');//如果要正确设置新列表元素的样式,则必须调用
}
其他的
{
警报(“主”);
警惕(“您的年龄=”+yourageVar);
警惕(“您的体重=”+weightVar);
$(“#contentlist”).empty();//清空我们在html中放置的列表元素
//使用phonegap设备api中的数据重新填充列表
$(“#内容列表”)。追加(您的年龄:“+yourageVar+” ”;
$(“#内容列表”)。附加(您的体重:“+weightVar+” ”;
$(“#contentlist”).listview('refresh');//如果要正确设置新列表元素的样式,则必须调用
}
$(“#contentlist”).listview('refresh');//如果要正确设置新列表元素的样式,则必须调用
}
函数showmainpagebutton(事件)
{
$('.maindivs').show();
$('.requireddivs').hide();
$('.updateddivs').hide();
}
函数showindexpagebutton(事件)
{
$.mobile.changePage(“index.html”,{transition:“slideup”});
}
试试这个:
//empty the list elements we've placed in the html
$("#contentlist li").remove();
//repopulate the list with data from phonegap's device api
$("#contentlist").append($("<li>Your Age: " + yourageVar + "</li>"));
$("#contentlist").append($("<li>Your Weight: " + weightVar + "</li>"));
$("#contentlist").trigger('create');
$("#contentlist").listview('refresh');
//清空我们在html中放置的列表元素
$(“#contentlist li”).remove();
//使用phonegap设备api中的数据重新填充列表
$(“#内容列表”)。追加($(“您的年龄:“+yourageVar+” ”);
$(“#内容列表”)。追加($(“您的体重:“+weightVar+” ”);
$(“#contentlist”).trigger('create');
$(“#内容列表”).listview(‘刷新’);