【问题标题】:how to check if Div exist in iframe [duplicate]如何检查 iframe 中是否存在 Div [重复]
【发布时间】:2015-03-08 18:46:07
【问题描述】:

大家好,我想检查 DIV 测试 是否存在于 iframe 显示警报中”

 <html>
  <body>
   <div id="test">test</div>
  </body>
</html>

我将此 html 文件加载到我的 iframe 中。如何检查 DIV 测试 是否存在?

<iframe src="1.html" width="80%" height="600" id="frameDemo"></iframe>

【问题讨论】:

    标签: html iframe


    【解决方案1】:
    var iframe = document.getElementById('frameDemo');
    var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
    var test = innerDoc.getElementById('test');
    
    if(test != undefined) {
    
        alert('Exists');
    
    }else{
    
        alert('Do no Exists');
    }
    

    :)

    【讨论】:

      猜你喜欢
      • 2012-07-20
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      相关资源
      最近更新 更多