如何綁定JSON數據到跨標籤我有一個像下面使用Javascript
[
{"label":"Finder1","count":3},
{"label":"Finder2","count":1},
{"label":"Finder1 & Finder2","count":1}
]
我想表明在span標籤在前端的數據JSON。 爲前:
Finder1 (3)
Finder2 (1)
Finder1 & Finder2 (1)
如何綁定JSON數據到跨標籤我有一個像下面使用Javascript
[
{"label":"Finder1","count":3},
{"label":"Finder2","count":1},
{"label":"Finder1 & Finder2","count":1}
]
我想表明在span標籤在前端的數據JSON。 爲前:
Finder1 (3)
Finder2 (1)
Finder1 & Finder2 (1)
試試這個:循環訪問數據並用它構造所需的字符串。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
var counter = 0;
$(function(){
\t var arr=[
\t {"label":"Finder1","count":3},
\t {"label":"Finder2","count":1},
\t {"label":"Finder1 & Finder2","count":1}
\t ];
var str='';
\t $.each(arr,function(index){
str=str+arr[index].label+" ("+arr[index].count+")<br>";
\t });
\t $("#data").html(str);
});
</script>
<body>
<span id="data"></span>
</body>
謝謝素集....有人預計 – sen