我正在我的网站上工作,我想使用Javascript制作一个表格,其行数等于数组game_names的长度。整个代码是:
var game_names = [
"first_game",
"second_game",
"third_game",
"fourth_game",
"fifth_game"
];
var parent = document.getElementById("games");
for (i=0;i<=10;i++){
var child = document.createElement("tr");
var node = document.createTextNode("hi!");
child.appendChild(node);
parent.appendChild(child);
}
在HTML代码中是一个空表(没有任何单元格)和id&#34;游戏&#34;。代码:
<table id="games" border="10px" align="center" width="100px">
</table>
由于某种原因,代码不会向表中添加任何行。我测试了代码在页面加载时运行(我将警报(&#34; hi!&#34;)放到代码的开头并且工作正常)。我不知道出了什么问题......
答案 0 :(得分:0)
代码似乎有效,但会产生奇怪的HTML。行(tr元素)应包含单元格(td元素)。并且你不会迭代你的game_names数组,你只需要从0迭代到10。请参阅下面的代码示例。
import requests
url = "https://storage.googleapis.com/****-171020.appspot.com/swift.txt"
querystring = {'GoogleAccessId':'storageadmin@****-171020.iam.gserviceaccount.com', 'Expires':'1503755879', 'Signature':'tlcHVRwbvMSxaIB6oO/TDXRDczXGFSE6ZXHmZbtCUMhjpos36/1KdKV7Lbmm7XtKsq42SFNksUIZLplyAMpkG8aMBuydeoJd+kvebLxK2k+AX8Xr2VVf5Aq/vVJrPGGYGD0iEN+bY264NIFbyJnlm0pthCVGtB5YqZJadCFDwPFWqi04312Jzzen1CXDY+saY0BabmXaZeCzINz7kV+aq0AJoS8taW0uqboYc1o4gCA6OPAswMr1E840a+II4HqkeOWcv7PiHEPdw/sgH3PR+TkGmjTAd9f8H6zJIFaT8DLbtsl7t3iAUM7Fvdtc9pGQt6KT0qUm9z3XfPEjP8OsTA=='}
payload = "Hello World!"
headers = {'Content-MD5': '7Qdih1MuhjZehB6Sv8UNjA==', 'Content-Type':'text/plain'}
response = requests.request("PUT", url, data=payload, headers=headers, params=querystring)
print(response.text)
答案 1 :(得分:0)
好的,我解决了这个问题。我把脚本放在桌子后面,因为它在头标签中!谢谢你的答案!