2017-03-05 79 views
0

我有一些Javascript代碼,它讀取已發佈的Google工作表並將其讀取到網頁中。出於某種原因,在Weebly嵌入這個int時,它只是不想接受它。據我所知,根本沒有任何元素。這是我的代碼,任何幫助都很棒。通過Javascript不工作將元素添加到Weebly

<!DOCTYPE html><!doctype html> 
<html> 
<head> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script type="text/javascript"> 
var spData = null; 
function doData(json) { 
    spData = json.feed.entry; 
} 
function readData(parent) { 
    var data = spData; 
    var ScoreObjs = []; 
    var ScoreObj = new Object(); 
    for(var r=4; r < data.length; r++) { 
     var cell = data[r]["gs$cell"]; 
     var val = cell["$t"]; 
     console.log(val); 
     if (cell.col == 1) { 
      ScoreObj.team1 = val; 
     } 
     else if (cell.col == 2) { 
      ScoreObj.team2 = val; 
     } 
     else if (cell.col == 3) { 
      ScoreObj.score1 = val; 
     } 
     else if (cell.col == 4) { 
      ScoreObj.score2 = val; 

      ScoreObjs.push(ScoreObj); 
      ScoreObj = new Object(); 
     } 
    } 
    toFormat(ScoreObjs); 
} 
function toFormat(obj) { 
    for (var x = 0; x < obj.length; x++) 
    { 
     var data = obj[x]; 
     var team1 = data.team1; 
     var team2 = data.team2; 
     var score1 = data.score1.toString(); 
     var score2 = data.score2.toString(); 

     var child1 = document.createElement("div"); 
     child1.className = "paragraph"; 
     document.body.appendChild(child1); 
     var child2 = document.createElement("strong"); 
     child1.appendChild(child2); 
     var child3 = document.createElement("font"); 
     child3.color = "#FFFFFF"; 
     child3.innerHTML = team1 + " vs " + team2 + "<br />ESEA Scrim"; 
     child2.appendChild(child3); 

     var child4 = document.createElement("font"); 
     child4.color = "#00FF00"; 
     child4.innerHTML = score1 + ":" + score2; 
     child1.appendChild(child4); 
    } 
} 
$(document).ready(function(){ 
    readData($("#data")); 
}); 

</script> 
<script src="https://spreadsheets.google.com/feeds/cells/1BSsomIQwFhifrFB8ybQ6xF0t-KdJNKtCBHotY3X8O98/1/public/values?alt=json-in-script&callback=doData"></script> 
</head> 
</html> 

回答

1

變化:

<script 
src="https://spreadsheets.google.com/feeds/cells/1BSsomIQwFhifrFB8ybQ6xF0t-KdJNKtCBHotY3X8O98/1/public/values?alt=json-in-script&callback=doData"></script> 

要:

<script id="data" 
src="https://spreadsheets.google.com/feeds/cells/1BSsomIQwFhifrFB8ybQ6xF0t-KdJNKtCBHotY3X8O98/1/public/values?alt=json-in-script&callback=doData"></script> 
0

這可能是因爲JavaScript代碼運行的第一,並呈現一些問題。我有同樣的問題。

將腳本標籤包含在頁腳而不是頭部。 實際上,您會在頁腳下找到默認的Weebly腳本標籤。添加您的自定義JavaScript代碼。

或 創建一個javascript(.js)文件,將其外部上傳到Assets中,然後將其添加到HTML頭文件以及其他默認的weebly腳本標記中。

例如。將這樣的添加(上傳到資產後)命名editsite.js JavaScript文件:

<script type="text/javascript" src="/files/theme/editsite.js"></script> 
 
\t

相關問題