我有一些 Json 数据。例如,考虑 endtime=316
、starttime=420
。所以我需要的是减去这些数据并将其显示在我的 html 页面中。我在警报中得到减去的值,但无法使用 jQuery 将此数据附加到 html 页面。
<强> JSFIDDLE
HTML
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<!--<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>-->
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<div data-role="page" id="index" tabindex="0" class="ui-page ui-page-theme-a ui-page-active">
<div data-role="content" class="ui-content">
<ul data-role="listview" class="ui-listview" id="ball">
</ul>
</div>
</div>
</body>
</html>
Javascript
var content='';
$.each(data,function(index,item){
var count = parseInt(item.endtime)-parseInt(item.starttime);
content += '<li><a href="index.html"><img src="'+item.thumb+'" class="userimage">';
count += '<span class="secondsbox" style="position:absolute; width:28px; height:15px; background: #485ac8; margin-top: 54px; margin-left: -4px;"><span style="position:absolute; font-size:12.52px; margin-left: 5px; color:#FFF; margin-top: -1px;" id="secdisplay"></span></span>';
content += '<h3 class="userurl">'+item.keywords+'</h3>';
content +='<p class="username">'+item.bombscount+'</p></a></li>';
});
$('#ball').append(content);
$('#ball').append(count);
$('#ball').listview('refresh');
最佳答案
您正在将 span
元素附加到 ul
。这是无效的,因为 ul
下只允许 li
元素。
根据 html 中的注释,也许您想要的是
content += '<span class="secondsbox" style="position:absolute; width:28px; height:15px; background: #485ac8; margin-top: 54px; margin-left: -4px;"><span style="position:absolute; font-size:12.52px; margin-left: 5px; color:#FFF; margin-top: -1px;" id="secdisplay">'+count+'</span></span>';
关于javascript - 如何在 Jquery 中追加两个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23844413/