js向文档中写数据 不懂 求助帮忙 谢谢

northern_wolf 2012-02-16 07:33:40
页面中有一个button按钮 当点击这个按钮 响应js 向页面追加一段话

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<input type="button" value="点我加美女" onclick="document.write('美女')"/>
</body>
</html>



当点击按钮的时候 美女是写入页面了 可是 按钮没了
我想点击按钮后 在按钮下面显示美女 按钮还是要存在页面原来位置 不知这个怎么弄 不懂 求帮助
...全文
100 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
northern_wolf 2012-02-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zzgzzg00 的回复:]
引用 4 楼 northern_wolf 的回复:
我要的是document.write()方法是不是不能写入页面数据
如果写了数据后 是不是页面原有的数据就没了

如果write方法可以 那怎么写? 谢谢

如果页面解析完成后再调用document.write方法他就会覆盖原来页面的所有东西了
[/Quote]
多谢了
似梦飞花 2012-02-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 northern_wolf 的回复:]
我要的是document.write()方法是不是不能写入页面数据
如果写了数据后 是不是页面原有的数据就没了

如果write方法可以 那怎么写? 谢谢
[/Quote]
如果页面解析完成后再调用document.write方法他就会覆盖原来页面的所有东西了
northern_wolf 2012-02-18
  • 打赏
  • 举报
回复
没人帮忙吗
northern_wolf 2012-02-16
  • 打赏
  • 举报
回复
我要的是document.write()方法是不是不能写入页面数据
如果写了数据后 是不是页面原有的数据就没了

如果write方法可以 那怎么写? 谢谢
northern_wolf 2012-02-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 thedolphin 的回复:]
HTML code
<div id="divAdd"></div>
[/Quote]
不好意思 页面上没有这个div
要动态的用js在页面上追加美女
用document.write方法是不是做不到?
Json1204 2012-02-16
  • 打赏
  • 举报
回复
<html>
<script type="text/javascript">
function WriteLine()
{
document.getElementById('meinv').innerHTML="美女";
}

</script>

<body>
<input type="button" onclick="WriteLine()" value="点击美女"/>
<div id="meinv"></div>
</body>
</html>
色拉油 2012-02-16
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function add() {
var div = document.getElementById("divAdd");
div.innerHTML="美女";
}
</script>
</head>
<body>
<input type="button" value="点我加美女" onclick="add();"/>
<div id="divAdd"></div>
</body>
</html>

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧