我使用Fusion Tables将网址存储到我的Google云端硬盘照片(存储在链接列中)。
我使用JavaScript查询Fusion Tables以获取所有网址,然后创建一个包含从数据中随机挑选的3个项目的表格。
我在下面添加的代码让我看到3张第一张照片......我试图切换线
contentStr += "<td><img src=" + item[j]+"></td>";
到
contentStr += "<td><img src=" + randomElement[j]+"></td>";
但它不起作用。有人能帮帮我吗?
<head>
<title>Test</title>
</head>
<body>
<div id="content"></div>
<script>
function handler(response) {
var maxFoto = response.rows.length
var contentStr = "<table>";
for (var i = 0; i < 3; i++) {
var item = response.rows[i];
var randomFoto = Math.floor(Math.random()*maxFoto);
var randomElement = item[randomFoto];
contentStr += "<tr>";
for (var j = 0; j < item.length; j++) {
contentStr += "<td><img src=" + item[j]+"></td>";
}
contentStr += "</tr>";
}
contentStr += "</table>";
document.getElementById("content").innerHTML = contentStr;
}
</script>
<script src="https://www.googleapis.com/fusiontables/v2/query?sql=SELECT%20Link%20FROM%20MYidTABLE&key=MYKEY&callback=handler&viewable=true"></script>
</body>
</html>
答案 0 :(得分:0)
我给自己一个答案......下面的代码完美无缺!
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="content"></div>
<script>
function handler(response) {
var maxFoto = response.rows.length
var contentStr = "<table>";
for (var i = 0; i < 3; i++) {
var randomFoto = Math.floor(Math.random()*maxFoto);
var item = response.rows[randomFoto];
contentStr += "<tr>";
for (var j = 0; j < item.length; j++) {
contentStr += "<td><img src=" + item[j]+"></td>";
}
contentStr += "</tr>";
}
contentStr += "</table>";
document.getElementById("content").innerHTML = contentStr;
}
</script>
<script src="https://www.googleapis.com/fusiontables/v2/query?sql=SELECT%20Link%20FROM%20MYTABLEID&key=MYKEY&callback=handler&viewable=true"></script>
</body>
</html>