js声明的遍历获取不到变量的值
iframe加载了一个页面,在加载iframe的页面获取iframe中let申明全局变量输出undefined,示例代码如下
点击按钮输出
undefined
admin
<iframe src="2.html" id="i"></iframe>
<input type="button" onclick="alert(i.contentWindow.role+'\n'+i.contentWindow.role1)" value="输出iframe中变量" />
2.html
<script>
let role = "admin";
var role1 = "admin";
</script>