如何使用JavaScript在DIV框内编写 [英] How to write inside a DIV box with javascript

查看:41
本文介绍了如何使用JavaScript在DIV框内编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个迷你游戏,其中一个玩家攻击一个npc,中间是一个我称之为(对数)的白盒(div),因为当玩家损坏/攻击该npc时,我希望在空白处记录发生的情况.

I'm making a mini-game where a player attacks a npc and in the center is a white box (div) that I call (log), because when the player damages/attacks the npc, I want to be able for that open white space to log what happened.

我正在使用getElementById(log),然后按照"document.write(您攻击了X npc")的方式添加了一些内容,但是它不起作用.

I'm using the getElementById(log) and then adding something along the lines of "document.write("You attacked X npc"), but its not working.

关于如何在框内而不是框外获取文本的任何想法?谢谢

Any idea on how I can get text INSIDE the box and not outside it? Thanks

推荐答案

document.getElementById('log').innerHTML += '<br>Some new content!';

<div id="log">initial content</div>

这篇关于如何使用JavaScript在DIV框内编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆