gpt4 book ai didi

javascript - document.getElementById ('articleTitle' ).value 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:20 24 4
gpt4 key购买 nike

我在我的网络应用程序中创建这些代码

<script type="text/javascript">
document.getElementById('articleTitle').value = "Ehsan" ;
</script>`

但结果我的输入没有值(value)

我的输入是:

<input id="articleTitle" name="articleTitle" class="input-xxlarge" 
type="text" placeholder="title">

我的javascript代码在html代码之上

最佳答案

在尝试检索元素之前,您需要确保该元素存在。例如,如果您的 script 位于 HTML 源代码中的 input 之上,则该元素在脚本运行时将不存在。

您可以将您的 script 标签移到 input 下方,这将起作用,或者使用某种“DOM ready”事件。 YUI team 建议将 script 标记放在 body 元素的末尾和 others建议只确保脚本位于它所使用的元素下方。

关于javascript - document.getElementById ('articleTitle' ).value 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13121510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com