下面是我的代码,但它还没有用。我该怎么做才能解决它?
特别参见function showtbl();
我的真正问题在于function showtbl();
,它不会显示表格的内容。
var tampilqr = function (kode) {
var url = 'http://www.playstore.co.id/p/download.html?qr='
var urlfix = url + kode
var keluar = '<a style="float:right;color:#999;text-decoration:none;background:#fff;width:20px;text-align:center;font-weight:bold;" onclick="rem();">X</a><br>'
var cek = keluar + '<iframe src="' + urlfix + '"></iframe>'
if (jscd.os == 'Android') {
window.location.href = urlfix;
} else {
uglipop({
class: 'dl',
source: 'html',
content: cek
});
}
}
var tampilss = function (kode) {
var url = 'https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/detil.html?ss='
var urlfix = url + kode
var keluar = '<a style="float:right;color:#999;text-decoration:none;background:#fff;width:20px;text-align:center;font-weight:bold;" onclick="rem();">X</a><br>'
var cek = keluar + '<iframe src="' + urlfix + '"></iframe>'
uglipop({
class: 'ss',
source: 'html',
content: cek
});
}
var rem = function () {
remove();
}
function tulis() {
document.getElementById("cari").placeholder = "cari aplikasi";
if (on_index = true) {
window.location = window.location.pathname + '?apps='
}
}
function showtbl() {
var img = "<img src='logo/"
var imgt = ".png'/>"
var li = "<br /> Link: <a href='?apps="
var lin = "'>http://playstore.co.id/?apps="
var link = "</a><br /> Terbit: "
var b = "<button type='button' class='btn btn-danger' onclick='tampilss(""
var bt = "");'>Screenshoot</button><br><button type='button' class='btn btn-success' onclick='tampilqr(""
var btn = "");'>Download</button>"
var A1 = "ss-clothes"
var A2 = "korselindo"
var A3 = "real-hiphop-shop"
/* if HTML, it must be:
<tr>
<td><img src="logo/ss-clothes.png" /></td>
<td>SS-Clothes<br /> Link: <a href="http://playstore.co.id?apps=ss-clothes">http://playstore.co.id?apps=ss-clothes</a><br /> Terbit: 23-06-2015</td>
<td><button class="btn btn-danger" onclick="tampilss("ss-clothes");" type="button">Screenshoot</button><br />
<button class="btn btn-success" onclick="tampilqr("ss-clothes");" type="button">Download</button></td>
</tr>
*/
var values = new Array(3);
values[1] = [img + A1 + imgt, A1 + li + A1 + lin + A1 + link, b + A1 + bt + A1 + btn];
values[2] = [img + A2 + imgt, A2 + li + A2 + lin + A2 + link, b + A2 + bt + A2 + btn];
values[3] = [img + A3 + imgt, A3 + li + A3 + lin + A3 + link, b + A3 + bt + A3 + btn];
var myTable = document.getElementById("myTable");
// IE7 only supports appending rows to tbody
var tbody = document.createElement("tbody");
// for each outer array row
for (var i = 1; i < values.length; i++) {
var tr = document.createElement("tr");
// for each inner array cell
// create td then text, append
for (var j = 0; j < values[i].length; j++) {
var td = document.createElement("td");
var txt = document.createElement("span");
txt.innerHTML = values[i][j];
td.appendChild(txt);
tr.appendChild(td);
}
// append row to table
// IE7 requires append row to tbody, append tbody to table
tbody.appendChild(tr);
myTable.appendChild(tbody);
}
}
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="UTF-8">
<title>Download Aplikasi</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="description" content="Toko aplikasi android Indonesia, apptoko, download aplikasi android .apk, appstore alternatif Google play store android market">
<link href="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/css/style.css" rel="stylesheet" />
<script src='https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/js/modernizr.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/js/jquery.dataTables.js"></script>
<link href="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/css/jquery.dataTables.min.css" rel="stylesheet" />
<script async="" src="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/js/bootstrap.min.js"></script>
<script async="" src="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/js/os.js"></script>
<link href="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/css/uglipop.css" rel="stylesheet" />
<script async="" src="https://dfe4876b91450c3efbab76e8d43c4a665e738138-www.googledrive.com/host/0B94BKN-oncxmfllMNlZkWGJTaF9QWmtLOVktR3djU3B0NGJuTFVwS2tDMS1jYzZkNEN6Y00/js/uglipop.js"></script>
</head>
<body onLoad="tulis();showtbl();">
<div id="atas">
<a href="javascript:window.location.replace('http://www.playstore.co.id?apps=')"><img src="http://1.bp.blogspot.com/-UON5Z5IIOus/VdH_gr8XRXI/AAAAAAAAAbY/Q-I4QfbZr9U/s1600/playstore-indonesia-logo.gif" /></a>
</div>
<table class="table table-striped" id="myTable">
<thead>
<tr>
<th>Logo</th>
<th>Nama App</th>
<th>Tindakan</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
<script>
$(document).ready(function () {
$("img").error(function () {
$(this).hide();
});
var table = $('#myTable').dataTable({
"oSearch": {
"sSearch": $.urlParam('apps'),
responsive: true
},
});
});
$.urlParam = function (name) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results && results[1].replace(/(^\s+|[^a-zA-Z ]+|\s+$)/g, ' ');
return results && results[1].replace(/\s+/g, ' ');
if (!results) {
return '//';
}
return results[1] || '';
};
</script>
</body>
</html>
我的真正问题在于function showtbl();
,它不会显示表格的内容。
请运行代码。我该怎么做才能解决它?
答案 0 :(得分:1)
我真正的问题在于函数showtbl();哪个不显示 表的内容。
如果删除不相关的空<tbody><tr></tr></tbody>
,则可以使用
<强> http://jsfiddle.net/yujpozf9/1/ 强>
dataTables不喜欢多个<tbody>
元素,当然也不喜欢具有奇数列的<tbody>
元素(如无)。
同时将responsive: true
移到它所属的位置并移除尾随'
- 你似乎非常关注IE7,尾随引号是一个IE7杀手。
var table = $('#myTable').dataTable({
responsive: true,
"oSearch": {
//"sSearch": $.urlParam('apps')
}
});
注释掉了$.urlParam
,因为这不是主要问题,我不完全明白你要做什么。你的代码是我见过的dataTables最特殊的用途之一(没有冒犯!) - 尝试阅读有关列渲染的内容,我认为你这样做会更开心 - &gt; https://datatables.net/examples/advanced_init/column_render.html - 一般的官方示例。
此外,您可以使用dataTables CDN代替使用谷歌驱动器 - 更容易维护和更改版本。我注意到你使用的是v1.10.2:
<script type="text/javascript" src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css"/>
答案 1 :(得分:0)
据我所知,datatables插件需要格式良好的表才能正常工作。你需要在doc中指定的thead和tbody标签(仔细阅读:https://www.datatables.net/manual/installation)。一旦完成,您就不必编写所有代码来过滤和显示您想要的内容。