加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

iframe中的Javascript日期选择器错误

发布时间:2020-12-14 18:28:38 所属栏目:资源 来源:网络整理
导读:我有一个页面 https://dev.leadformly.com/datepicker有一个iframe 在那个特定的”中,我通过以下代码通过ajax调用动态编写HTML代码. script $(document).ready(function(){ $.post(URL,function (data) { //here it retruns the HTML code $("body").html('i
我有一个页面 https://dev.leadformly.com/datepicker有一个iframe
在那个特定的”中,我通过以下代码通过ajax调用动态编写HTML代码.
<script>
  $(document).ready(function(){
    $.post(URL,function (data) { //here it retruns the HTML code
          $("body").html('<iframe style="width:100%;height:384px;"></iframe>');
          $("body iframe")[0].contentDocument.write(data.democode);
        },'json'
      );
    });
</script>

现在,当我点击日期选择器时,它将在控制台中抛出一个错误,如:

Uncaught TypeError: Cannot read property 'top' of undefined

你能帮我解决这个问题吗?或者只是解释原因,这将有助于我解决它

解决方法

您收到此错误是因为您尝试从包含它的父DOM访问iFrame的内部DOM.来自父DOM的“click”事件无法调用子iFrame中的元素.

我可以问你为什么要在这种情况下使用iFrame吗?我几乎可以向你保证,最好不要使用它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读