Javascript window.frames[1].document.getElementById无法读取属性';文件';未定义的

Javascript window.frames[1].document.getElementById无法读取属性';文件';未定义的,javascript,Javascript,我有js问题,或者我不知道我看不到问题 当我检查 window.frames[1].document.getElementById('GroupPolicyIdentity.policyStartDate').value; 在控制台中,我看到了值,但在js代码中我得到了错误 Uncaught TypeError: Cannot read property 'document' of undefined. 我正在努力做到这一点 var policyStartDate = window.fra

我有js问题,或者我不知道我看不到问题

当我检查

window.frames[1].document.getElementById('GroupPolicyIdentity.policyStartDate').value;
在控制台中,我看到了值,但在js代码中我得到了错误

Uncaught TypeError: Cannot read property 'document' of undefined.
我正在努力做到这一点

var policyStartDate = 
window.frames[1].document.getElementById('GroupPolicyIdentity.policyStartDate').value;
你能帮我吗?
谢谢。

在加载所有帧后,您可能想这样尝试

<script type="text/javascript">
window.onload=function(){
    var policyStartDate = window.frames[1].document.getElementById('GroupPolicyIdentity.policyStartDate').value;
    alert(policyStartDate);
}
</script>

window.onload=function(){
var policyStartDate=window.frames[1]。document.getElementById('GroupPolicyIdentity.policyStartDate')。值;
警报(policyStartDate);
}
这对我来说很有效…尽管框架样本不同。出现以下错误的原因:

未捕获的TypeError:无法读取未定义的属性“document”


是因为没有加载帧。如果您将其本身检查为
window.frames.length
,则结果为
0
我的问题通过document.getElementById('GroupPolicyIdentity.policyStartDate').value解决。我不知道它是怎么工作的,但答案是。
谢谢大家

是的,我肯定,这是一个老项目,页面中有两个框架。我已经看到数据了。你能检查一下
窗口.框架.长度吗?@devgirl你能告诉我你是如何在脚本标签内用JS…检查的吗??