js写无空白页
嘿,我知道我问这个问题可能看起来像个十足的傻瓜,但我真的从来不知道,我发现没有任何东西可以帮助我。 我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎你有一些拼写错误,JS 区分大小写,正确的函数名称是
getElementById
(大写“B”),并且你必须设置innerHTML
属性而不是“innherHTML” :Seems that you have some typos, JS is case sensitive, the correct function name is
getElementById
(uppercase "B") and you have to set theinnerHTML
attribute not "innherHTML":如果您想在页面加载时将文本放在那里,您可以使用 document.write:
您还可以设置innerHTML 属性,但是您必须确保脚本在浏览器读取元素后运行。 此外,您还必须在 getElementById 调用中使用元素的 id:
编辑:
如果您希望文本显示在同一行,您可能需要将 div 更改为 span:
If you want to put the text there while the page is loading, you use document.write:
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:
Edit:
If you want the text to displayed on the same line, you may want to change the div to a span: