iframe中的jquery目标元素不起作用

时间:2016-10-05 12:56:37

标签: jquery iframe

此代码确实隐藏了完整的iframe,因此我将iframe设为正确

<script>
$(document).ready(function(){
      $('iframe[id^="_Liferay_widget"]').hide();
})
</script>

但是这段代码并没有隐藏iframe中的所有div。

<script>
$(document).ready(function(){
      $('iframe[id^="_Liferay_widget"]').contents().find('div').hide();
})
</script>

我做错了什么? iframe位于maindomain的子域中,在safari的开发工具中,我对已关闭的本地文件有限制。我在控制台中看不到任何消息。

1 个答案:

答案 0 :(得分:1)

尝试使用此代码进行定位:

<a
     xlink:href="../templates/QRCode.html"
     transform= (removed to ease viewing)
     id= (removed to ease viewing)
     target="_blank">
    <path
       style= (removed to ease viewing)
       d= (removed to ease viewing)
       id= (removed to ease viewing)
       inkscape:connector-curvature="0" />
  </a>
  <a
     transform= (removed to ease viewing)
     id= (removed to ease viewing)
     target="_blank"
     xlink:href="../templates/RoomInformation.html">
    <path
       style= (removed to ease viewing)
       d= (removed to ease viewing)
       id= (removed to ease viewing)
       inkscape:connector-curvature="0" />
  </a>

只需添加要隐藏的DIV ID即可。