如何从 iframe 中获取元素?我想要一个元素在框架中的属性为真时;它显示一个文本,否则显示另一个文本;(对不起英语不好!)
像那样:
<!DOCTYPE html>
<html>
<head>
<title>document</title>
</head>
<body>
<iframe id="frame" src="">
<!--we think in frame there is a span tag with button id-->
<span id="button" aria-passed="true">sss</span>
</iframe>
<br>
<!--if its true-->
<p id="content1" style="display:none;">
true
</p>
<!--if its false-->
<p id="content2" style="display:none;">
false
</p>
<!--now we want that, if aria-passed=true show content1 else content2.-->
<script type="text/javascript">
var Frame = document.getElementById('frame');
if(new RegExp ("true","gim").test(frame.contentWindow.document.getElementById('button').aria-passed="true") == true) {
document.getElementById('content1').style.display="block";
}
else {
document.getElementById('content2').style.display="block";
}
</script>
</body>
</html>
现在我想说为什么这段代码不起作用???有任何想法吗?