Web_Design 板


LINE

以下是程式码 新增那个功能不能用,不知道是哪里出了问题~? 检视成绩的时候印出的东西也怪怪的,会印出define,抓的资料也不完全 不知道是哪里出了问题~? <!doctype html> <html> <head> <meta charset="utf-8"> <title>DOM使用</title> <style> body,table,th,td{font-size:15px;} #tabScore {border-collapse:collapse;} #tabScore th{padding:5px} #tabScore td{padding:5px} </style> <script> function disScore(){ var tab=document.getElementById("tabScore"); var rows=tab.rows; for(var i=1;i<rows.length;i++){ var name=rows[i].childNodes[0].innerText; var java=rows[i].childNodes[1].innerText; var html=rows[i].childNodes[2].innerText; var sql=rows[i].childNodes[3].innerText; var count=rows[i].childNodes[4].innerText; document.write(name+':'+java+","+html+","+sql+","+count); } } function addScore(){ var name=document.getElementById("userName").value; var java=document.getElementById("java").value; var html=document.getElementById("html").value; var sql=document.getElementById("sql").value; var count=parseInt(java)+parseInt(html)+parseInt(sql); var tab=document.getElementById("tabScore"); var row=tab.insertRow(); var td_name=row.insertCell(); td_name.style.textAlign="center"; td_name.innerText=name; var td_java=row.insertCell(); td_java.style.textAlign="center"; td_java.innerText=java; var td_sql=row.insertCell(); td_sql.style.textAlign="center"; td_sql.innerText=sql; var td_count=row.insertCell(); td_count.style.textAlign="center"; td_count.innerText=count; } </script> </head> <body> 姓名:<input type="text" id="userNmae" size="10"/>&nbsp;&nbsp; Java:<input type="text" id="java" size="3" maxlength="2"/>&nbsp;&nbsp; HTML:<input type="text" id="html" size="3"maxlength="2"/>&nbsp;&nbsp; Sqlserver:<input type="text" id="sql" size="3"maxlength="2"/>&nbsp;&nbsp; <input type="button" value="增加" onclick="addScore()"/> <hr size="3"/> <br> <input type="button" value="检视表中成绩" onclick="disScore();"> <hr size="3"> <table id="tabScore" width="470" border="1"; bordercolor="#003399" align="center"> <tr bgcolor="#0099FF"> <th>姓名</th><th>JAVA</th><th>HTML</th><th>SQLServer</th><th>总成绩</th> </tr> <tr> <td align="center">张三</td> <td align="center">87</td> <td align="center">92</td> <td align="center">79</td> <td align="center">258</td> </tr> <tr> <td align="center">李四</td> <td align="center">54</td> <td align="center">92</td> <td align="center">87</td> <td align="center">247</td> </tr> <tr> <td align="center">王五</td> <td align="center">94</td> <td align="center">81</td> <td align="center">67</td> <td align="center">269</td> </tr> </table> </body> </html> --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.246.201.24
1F:→ emn178:我想是document.write 之後, 资料就被清掉了? 03/29 17:11
2F:→ emn178:用console.log或alert看看 03/29 17:12
3F:→ supercygnus:试了好久,发现 03/29 21:51
4F:→ supercygnus:var name=rows[i].childNodes[0].innerText;根抓不到 03/29 21:51
5F:→ supercygnus:东西,到底要怎麽抓啊 03/29 21:51
6F:→ supercygnus:新增资料目前可以跑出来但是还是有问题 03/29 22:40
7F:→ supercygnus:Html栏位值不会出来 如图那样,到底是哪里出错了呢? 03/29 22:41
8F:→ supercygnus:http://0rz.tw/1JlhO 03/29 22:42
9F:推 s25g5d4:innerHTML 03/30 00:01
10F:推 s25g5d4:一个断行或空白字元也算一个node 所以你可能抓到断行 03/30 00:07
11F:推 s25g5d4:http://jsfiddle.net/PNkbu/1/ 03/30 00:41
12F:→ s25g5d4:参考: http://tinyurl.com/cxtpcgp 03/30 00:42
13F:→ dlikeayu:我想先问资料怎麽来的 04/01 08:10
14F:→ dlikeayu:以目前趋势,资料来源是你能掌握的话 Html用来呈现 04/01 08:11
15F:→ dlikeayu:资料还是用Json Bson来规划比较好 04/01 08:11
16F:→ dlikeayu:无论在效能上或是filter都有很大的帮助 04/01 08:14
17F:→ dlikeayu:不然这样由後台产出的资料已经丢到排版上,再反过来用js 04/01 08:16
18F:→ dlikeayu:抓"view"里的资料做排版,有点绕道 除非资料来源不可控 04/01 08:16







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job 或 站内搜寻

TOP