你好,我是一名新手,正在使用JavaScript和HTML/CSS。
我不明白为什么我的脚本在Safari上能够运行,但在Chrome和Firefox上却不能运行...有什么想法吗?
编辑:在Chrome和Firefox中,ul和li元素都不显示...之前的警告也不起作用。我将检查控制台中的错误并再次编辑帖子。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="patients" style="text-align:center">
</div>
<script type="text/javascript">
$.getJSON("http://www.url.com/json",
function(data) {
var items = [];
alert(data[1].patient);
alert(data[1].hr);
$.each(data, function(index, val) {
items.push('<li id="' + index + '">' + val.patient + '<div style="display: none" id="'+val.patient+'"></div></li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('#patients');
});
</script>
</body>
</html>
'class'
周围的引号。对象属性名称不应该加上引号。 - Fabrício Matté