有没有办法为 jquery 手风琴中的 and 语句创建一个循环,这样我就可以遍历我的 JSON。
下面的代码使 JSON 工作,所以我希望 JSON 中的数据填充我的 jquery 手风琴。只是不知道如何处理手风琴需要的 h3 和 div 标签。
<html>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<head>
<link rel="stylesheet" href="jquery-ui-1.8.23.custom/development-bundle/themes/base/jquery.ui.all.css">
<script src="jquery-ui-1.8.23.custom/development-bundle/jquery-1.8.0.js"></script>
<script src="jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.core.js"></script>
<script src="jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.widget.js"></script>
<script src="jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.mouse.js"></script>
<script src="jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.selectable.js"></script>
<script src="jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.accordion.js"></script>
<link rel="stylesheet" href="jquery-ui-1.8.23.custom/development-bundle/demos/demos.css">
<script type='text/javascript' src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script>
$(function() {
$( "#accordion" ).accordion();
});
</script><script>
$(document).ready(function(){
/* call the php that has the php array which is json_encoded */
$.getJSON(ReturnPlacesJSON.php, function(data) {
/* data will hold the php array as a javascript object */
$.each(data, function(key, val) {
var latlng = new google.maps.LatLng(val.xcoord, val.ycoord);
var title = (val.title)?val.title:""
var icon = 'http://shanewmiller.com/Specials/images/beermug.png';
var special = val.Description;
var end = (val.endtime)?val.endtime:""
var start = (val.starttime)?val.starttime+" - ":""
var day = (val.day)?val.day:""
var html = val.name + val.address + special + day + start + end;
$('<h3 />').html(special).appendTo('#accordion');
$('<div />').html(val.name + ' ' + val.address).appendTo('#accordion');
});
});
});
</script>
</head>
<body>
<div id="accordion">
</div>
</body></html>