PhoneGap - 请告知保存功能不起作用的原因
PhoneGap - please advise why the save function does not work
>我用VS2010写了一个phonegap小例子,但我不知道为什么我不能使用window.locaStorage来存储和检索简单值
请检查并让我知道出了什么问题
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Cordova WP7</title>
<link rel="stylesheet" href="jquery.mobile-1.1.0.css" type="text/css"/>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script src="jquery.mobile-1.1.0.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready",onDeviceReady,false);
// once the device ready event fires, you can safely do your thing! -jm
function onDeviceReady()
{
//document.getElementById("welcomeMsg").innerHTML += "Cordova is ready! version=" + window.device.cordova;
console.log("onDeviceReady. You should see this message in Visual Studio's output window.");
//navigator.notification.alert("Hello World");
};
$(function(){
$("#savebtn").click(function(){
window.localStorage.setItem("modelname", $("#modelname").val());
});
$("#androidpg").live("pageshow", function () {
var moname = ""
moname = window.localStorage.getItem("modelname");
if (moname.length > 0) {
$("#modelname").val(moname);
}
});
});
</script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="content">
This Demo can run on:
<ul>
<li>iOS</li>
<li>Android</li>
<li>BlackBerry</li>
<li>Windows Mobile</li>
</ul>
<a href="#androidpg" data-role="button">Goto Android Page</a>
</div>
<div data-role="footer" data-position="fixed">
<h4>All Rights Reserved</h4>
</div>
</div>
<div data-role="page" id="androidpg">
<div data-role="header">
<h1>Android</h1>
</div>
<div data-role="content">
<h1>Android Page</h1>
<label for="modelname">Enter Model Name:</label>
<input type="text" name="modelname" id="modelname" value="" />
<a href="#savebtn" data-role="button">Save</a>
</div>
<div data-role="footer" data-position="fixed">
<h4>All Rights Reserved</h4>
</div>
</div>
</body>
</html>
谢谢
id
选择器 #savebtn
查找 id 为 savebtn
的元素。您的链接<a href="#savebtn" data-role="button">Save</a>
没有 id savebtn
(您发布的代码中没有元素)。向定位点添加 ID。 <a href="#savebtn" id="savebtn" data-role="button">Save</a>
您可能需要注册"tap"或"vclick"处理程序才能触发处理程序。
相关文章:
- 使用复杂数组时Jquery自动完成功能不起作用
- 为什么我的流星每个功能都不起作用
- jQuery点击功能在获取请求后不起作用
- 切换功能不起作用
- 为什么不是'我的修剪功能不起作用
- Angular UI Select2指令搜索功能不起作用
- j查询点击功能在手风琴菜单链接上不起作用
- 为什么这个排序功能在 Safari 中不起作用
- 控制器功能在 Angular.js 中不起作用
- AngularJS 路由功能不起作用
- JavaScript更新功能不起作用
- ScriptX 打印功能在 IE8 中不起作用
- JS表单验证功能不起作用
- 本地存储功能中的图像不起作用
- 复选框树视图功能不起作用
- Web音频-AudioParam调度功能不起作用
- 功能的禁用/启用按钮;不起作用
- JavaScript/jQuery:获取选择功能在Firefox和Chrome中不起作用
- 复选框单击功能不起作用
- Ckeditor插件功能在使用setData(“hai”)之后不起作用;