作者coilion9670 (runrunder)
看板Ajax
标题[问题] 初学者对於document.write的疑惑...
时间Tue May 6 13:35:38 2014
小弟当踏到javascript的范畴内
动手写了一个button按了之後
onclick="document.write('Hello</b>')"
之类的这样的东西
网路上找了许久范例跟document.write的说明
像是
http://taiwantc.com/js/js_tut_b_document0.htm
里面提到"document.write 写入的资料就会伸延到文件的尾部"
里面范例测试的确也是如此
但自己动手写一个却是页面洗掉print出Hello
code:
<head></head>
<body>
<form>
<input type="button" value="hello" onClick="document.write('Hello</b>')">
</form>
</body>
按了之後我的button就消失了没有印在文章尾阿...
是我理解错误吗....请教各位QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 112.105.52.20
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Ajax/M.1399354541.A.8AC.html
1F:→ danny8376:在文件"解析完成前" document.write会往尾巴塞内容 05/06 15:14
2F:→ danny8376:一旦解析完成後 document.write就会把页面清掉 05/06 15:15
3F:→ coilion9670:那要如何保留可以像网路上范例那样印在文章尾呢? 05/06 15:17
4F:→ danny8376:别塞click 让他在页面里 05/06 20:52
5F:→ white9cat:$('form').html($('form').html()+'hello</b>') 05/06 20:52
6F:→ danny8376:如果是要按钮增加内容的话要用append 05/06 20:53
7F:→ white9cat:我的写法要配jQuery,纯js应该也有办法 05/06 20:53
8F:→ danny8376:楼上... 他这怎看都没jQuery啊www 05/06 20:53
9F:→ white9cat:但我记得纯js也有办法做同样的事,只是写法不太一样。 05/06 20:56
10F:→ danny8376:纯js用innerHTML 不过这做法不推 如果整页内容很大的话 05/06 21:01
11F:→ danny8376:用这方法很耗记忆体 还是append好些 05/06 21:02
12F:→ coilion9670:谢谢各位刚刚用append写成功了,只能说我会错网 05/06 21:37
13F:→ coilion9670:站范例的意思 05/06 21:38
14F:推 mrbigmouth:jQuery能做到的事纯js都有办法做到 只是要多写很多 05/06 22:10
15F:推 conanist:推楼上,新手先学好JAVASCRIPT 就UI 语法 呼叫服务 05/22 00:02