这是html代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css"/>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="js/lib/cordova-2.7.0.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/converter/Temperature.js"></script>
<script type="text/javascript" charset="utf-8" src="js/converter/TemperatureContents.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
alert("fgfgf");
});
</script>
</head>
<body>
<div data-role="page" id="converterListPage" data-theme="b">
<div data-role="header">
<h1>UNIT CONVERTER</h1>
</div>
<div data-role="content" data-theme="e">
<ul data-role="listview" data-inset="true">
<li><a href="#" id="tempButton">TEMPERATURE</a></li>
<li><a href="#">WEIGHT</a></li>
<li><a href="#">CURRENCY CONVERTER</a></li>
</ul>
</div>
</div>
<div data-role="page" id="temperatureContents" data-theme="e">
<div data-role="content">
<p>sdfsdsdsds</p>
</div>
</div>
</body>
</html>
温度.js
$('#converterListPage').live('pageinit', function() {
alert("converter list page");
$("#tempButton").off('click').on('click',function()
{
//$.mobile.changePage("#temperatureContents",null,true,true);
alert("button clicked");
});
});
在这一行出现错误:
$('#converterListPage').live('pageinit', function()
错误是:
07-31 11:01:42.405: E/Web Console(730): TypeError: 表达式'$('#converterListPage').live' [undefined] 的结果不是函数。在 file:///android_asset/www/js/converter/Temperature.js:10 使用后:
yes now there is no error: but when putting this line in DOM READY:
$(document).ready(function()
{
alert("fgfgf");
$("#tempButton").off('click').on('click',function()
{
// $.mobile.changePage("#temperatureContents",null,true,true);
alert("button clicked");
});
它可以工作,但是当放入 temperature.js 时,它不会触发事件:
$('#converterListPage').on('pageshow', function() {
alert("converter list page");
$("#tempButton").off('click').on('click',function()
{
// $.mobile.changePage("#temperatureContents",null,true,true);
alert("button clicked");
});
});