我有這個簡單的HTML(我主持我自己的文件和它的作品)jQuery Mobile的頁面注入
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="JQM/jquery.mobile-1.0.1.min.css" />
<script src="JQM/jquery.js"></script>
<script src="JQM/jquery.mobile-1.0.1.min.js"></script>
<script src="pages.js"></script>
</head>
<body onload="main_page();">
<div data-role="page">
<div data-role="header">
<h1>My Title</h1>
</div>
<div id="main_div" data-role="content">
</div>
</div>
</body>
</html>
在onload事件我要調用這個函數,並添加JS到ID生成的內容=」 main_div「或data-role =」content「
function main_page(){//trips menu
var this_page =' ';
var this_body='';
this_body += '<ul data-role="listview" data-inset="true" data-filter="true">';
this_body += "<li><a href=\"#\">Check my Inbox</a></li>";
this_body += "<li><a href=\"#\">Tutors/ Post Tutors</a></li>";
this_body += "<li><a href=\"#\">Books/Post Books</a></li>";
this_body += "<li><a href=\"#\">Invite friends</a></li>";
this_body += "<li><a href=\"#\">Forum</a></li>";
this_body += '</ul>';
this_page += this_body;
var $page = $(pageSelector),
$content = $page.children(":jqmData(role=content)");
$page+=this_page;
$.mobile.changePage(#,$page);
}
這只是我必須做的一個簡單例子。但無論怎樣我不工作....
'pageSelector'從哪裏來? – Cranio