這裏是html代碼:我.live功能不點火,給我的錯誤使用jQuery 1.10.1
<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>
Temperature.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: Result of expression '$('#converterListPage').live' [undefined] is not a function. at file:///android_asset/www/js/converter/Temperature.js:10 after using on :
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");
});
});
你不應該在JQM中使用'.ready'。 – Omar