并感谢您查看我的问题。我是 HTML、JQuery 和 JSON 的新手。我正在尝试通过一些在线教程和 www.lynda.com 培训自学。我正在尝试制作一个词汇表,在页面上动态显示术语列表,单击时会在标题中显示术语及其下方的定义。经过搜索和实验,我取得了进展,我的 ul 从 JSon 对象填充并链接到显示页面。但我不知道如何让显示页面正常工作。我认为答案在这里:http: //jquerymobile.com/demos/1.1.1/docs/pages/page-dynamic.html但我似乎无法完成,即使在 Dreamweaver 中也是如此。
这是 JSFiddle:http: //jsfiddle.net/LParker/PSntK/3/
HTML:
<!-- Glossary -->
<div data-role="page" id="glossary">
<div data-role="header">
<h3>
Glossary
</h3>
</div>
<ul data-role='listview' data-inset='true' id='resultsList'>
<!-- keep empty for dynamically added items -->
</ul>
</div>
<!-- display -->
<div data-role="page" id="display">
<div data-role="header">
<h3>
Name Goes Here
</h3>
</div>
<div data-role="content">
<div>Definition goes here</div>
</div>
JavaScript:
var jsonObject = {
"results": [{
"term": "Term One",
"definition": "This is the definition for Term Two",
},
{
"term": "Term Two",
"definition": "This is the definition of Term Two",
}, {
"term": "Term Three",
"definition": "This is the definition for Term Three",
}],
"ok": "true"
}
var resultLength = jsonObject.results.length;
var listItems = [];
for (var i = 0; i < resultLength; i++) {
var term = jsonObject.results[i].term;
//Add result to array
listItems.push("<li><a href='#display'>" + term + " </a></li>");
}
//Append array to list and refresh
$('#resultsList').append(listItems.join(' '));
$('#resultsList').listview('refresh');
任何帮助,将不胜感激!