Javascript can';t为html输入标记分配id值

Javascript can';t为html输入标记分配id值,javascript,html,input,Javascript,Html,Input,我必须这样做: 任务很简单:在html中为输入标记分配一个id,并通过javascript获取值。我在我的应用程序上也做了同样的事情(代码非常大,所以我不会在这里发布!),但它不起作用。 我有点像: <div id="old_pw_sp" class="col-xs-7"> <input type="password" id="current_password"/> </div> 但我一直在犯错误: TypeError: document.getEleme

我必须这样做:

任务很简单:在html中为输入标记分配一个id,并通过javascript获取值。我在我的应用程序上也做了同样的事情(代码非常大,所以我不会在这里发布!),但它不起作用。 我有点像:

<div id="old_pw_sp" class="col-xs-7">
<input type="password" id="current_password"/>
</div>
但我一直在犯错误:

TypeError: document.getElementById(...) is null
如果我使用firefox analyzer分析输入标记,我会得到以下结果:

<div id="old_pw_sp" class="col-xs-7">
    <input type="password">
</div>

身份证不在那里,但我不知道为什么。有人能帮我吗

编辑! 我很愚蠢:我正在编辑一个文件,而我正在加载另一个应用程序。现在它工作得很好

使用方法如下

 <div id="old_pw_sp" class="col-xs-7">
 <input type="password" id="current_password"/>
</div>
<div id="click_here" onclick="showPassword();">Click</div>

function showPassword(){
 alert(document.getElementById("current_password").value);
}

点击
函数showPassword(){
警报(document.getElementById(“当前密码”).value);
}

您会在文件中搜索字符串“current_password”并查看它是否在两个位置都匹配吗?我认为您有重复的idRefresh绕过缓存(Windows上的shift+F5),或者关闭浏览器并重新加载页面,或者完全清除缓存并重新加载。您还可以在页面上进行另一个更改,然后查看该更改是否已实际加载。检查是否有其他js代码操纵您的html。从将输入type=“password”更改为type=“text”(只是为了测试)开始更新您的小提琴,试试看
 <div id="old_pw_sp" class="col-xs-7">
 <input type="password" id="current_password"/>
</div>
<div id="click_here" onclick="showPassword();">Click</div>

function showPassword(){
 alert(document.getElementById("current_password").value);
}