js写无空白页

发布于 2024-07-16 02:00:38 字数 620 浏览 12 评论 0原文

嘿,我知道我问这个问题可能看起来像个十足的傻瓜,但我真的从来不知道,我发现没有任何东西可以帮助我。 我使用 javascript 生成了这个字符串,我想将其附加到我现有的网页上。 我用过 document.write(); 或者只是 document.getElementbyId('').append(); 我只是无法让它将文档附加到我选择的 id...

我有:

<p><div id="dT">Bienvenido, Hoy es :: <div id="fecha" class="reloj"></div></div></p>

并且我想在 :: 之后附加结果字符串

js 位于一个单独的文件中,但它开始在加载时工作。


编辑答案

我没有,但我只是尝试了,仍然没有发生,甚至没有错误=/这就是我所做的:

x = Hoy + " " + es + " dia " + dia + " del " + yr;

document.getElementbyId('dT').innherHTML += x;

hey I know I may seem like a complete fool for asking this question but I truly have never known and nothing I find helps me. I have this string generated using javascript and I want to append it to my existing web page on the fly. I've used document.write(); or just document.getElementbyId('').append(); and I just can't get it to append the document to my selected id...

I have:

<p><div id="dT">Bienvenido, Hoy es :: <div id="fecha" class="reloj"></div></div></p>

and I want to append the resulting string after the ::

The js is in a separate file but it starts working onload.


Edit to answer

I hadn't, but I just tried, still nothing happen, not even an error =/ this is what I did:

x = Hoy + " " + es + " dia " + dia + " del " + yr;

document.getElementbyId('dT').innherHTML += x;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮颜 2024-07-23 02:00:38

似乎你有一些拼写错误,JS 区分大小写,正确的函数名称是 getElementById (大写“B”),并且你必须设置 innerHTML 属性而不是“innherHTML” :

document.getElementById('dT').innerHTML += x;

Seems that you have some typos, JS is case sensitive, the correct function name is getElementById (uppercase "B") and you have to set the innerHTML attribute not "innherHTML":

document.getElementById('dT').innerHTML += x;
ゝ杯具 2024-07-23 02:00:38

如果您想在页面加载时将文本放在那里,您可以使用 document.write:

<p><div id="dT">Bienvenido, Hoy es :: <div id="fecha" class="reloj">
<script type="text/javascript">

x = Hoy + " " + es + " dia " + dia + " del " + yr;

document.write(x);

</script>
</div></div></p>

您还可以设置innerHTML 属性,但是您必须确保脚本在浏览器读取元素后运行。 此外,您还必须在 getElementById 调用中使用元素的 id:

x = Hoy + " " + es + " dia " + dia + " del " + yr;

document.getElementById('fecha').innerHTML = x;

编辑:
如果您希望文本显示在同一行,您可能需要将 div 更改为 span:

<p><div id="dT">Bienvenido, Hoy es :: 
<span id="fecha" class="reloj"></span>
</div></p>

If you want to put the text there while the page is loading, you use document.write:

<p><div id="dT">Bienvenido, Hoy es :: <div id="fecha" class="reloj">
<script type="text/javascript">

x = Hoy + " " + es + " dia " + dia + " del " + yr;

document.write(x);

</script>
</div></div></p>

You can also set the innerHTML property, but then you have to make sure that the script runs after the element has been read by the browser. Also you have to use the id of the element in the getElementById call:

x = Hoy + " " + es + " dia " + dia + " del " + yr;

document.getElementById('fecha').innerHTML = x;

Edit:
If you want the text to displayed on the same line, you may want to change the div to a span:

<p><div id="dT">Bienvenido, Hoy es :: 
<span id="fecha" class="reloj"></span>
</div></p>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文