<script src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var jqxhr = $.getJSON("./data_json/Filter_json/j97hq-92dsm_n.json", function () {
console.log("success");
})
//如果有這檔案會印出success
//$.getJSON("./data_json/Resonator_json/tl8oh-63gm2.json", function (json) {
// alert("JSON Data: " + json.name);
//});
//讀出json屬性的值,name是KEY,根據自己KEY定義改
//debugger;
var info = document.querySelector('.info');
var str = "";
$.getJSON("./data_json/Filter_json/j97hq-92dsm_n.json", function (json_data) {
// console.log(JSON.stringify(json));
// debugger;
var len = json_data.length; //資料比數
if (len != 0) {
for (var i = 0; i < len; i++) {
// var content = '<tr>' + '<td>名稱:' + datastr[i].name + ' </td>' + '<td>value_a:' + datastr[i].value_a + ' </td>' + '<td>value_b:' + datastr[i].value_b + ' </td>' + '<td>value_c:' + datastr[i].value_c + ' </td>' + '<td>value_d:' + datastr[i].value_d + ' </td>' + '<td>value_e:' + datastr[i].value_e + ' </td>' + '</tr>';
var content = "";
if (json_data[i].value_url != 'Null') {
content = '<tr>' + '<td> <a href="./pdf/Datasheet/' + json_data[i].value_url + '" target="_blank"> ' + json_data[i].name + '<img src="./img/pdf-download.png" width="51px" height="35px"></a></td>' + '<td>' + json_data[i].value_a + ' </td>' + '<td>' + json_data[i].value_b + ' </td>' + '<td>' + json_data[i].value_c + ' </td>' + '<td>' + json_data[i].value_d + ' </td>' + '<td> </td>' + '</tr>';
} else {
content = '<tr>' + '<td>' + json_data[i].name + ' </td>' + '<td>' + json_data[i].value_a + ' </td>' + '<td>' + json_data[i].value_b + ' </td>' + '<td>' + json_data[i].value_c + ' </td>' + '<td>' + json_data[i].value_d + ' </td>' + '<td> </td>' + '</tr>';
}
//console.log(content);
str += content;
};
} else {
var content = '<tr>' + '<td>Null</td>' + '<td>Null</td>' + '<td>Null</td>' + '<td>Null</td>' + '<td>Null</td>' + '<td>Null</td>' + '</tr>';
//console.log(content);
str += content;
}
info.innerHTML += str;
});
//將JSON印成字串
});
</script>
----Html-----
<div class="table-responsive">
<nobr>
<table class="table">
<thead>
<tr>
<th scope="col">Part</th>
<th scope="col">Frequency</th>
<th scope="col">Bandwidth</th>
<th scope="col">Lid Symbol</th>
<th scope="col">Dimension</th>
<th scope="col">Automotive</th>
</tr>
</thead>
<tbody class="info">
</tbody>
</table>
</nobr>
</div>
沒有留言:
張貼留言