【问题标题】:Why element is hiding but doesn't load content into iframe为什么元素隐藏但不将内容加载到 iframe
【发布时间】:2017-08-22 09:59:52
【问题描述】:

需要帮助 :) 我有一段代码,如下所示:

<head>
        <meta charset="utf-8">
        <title></title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href='https://fonts.googleapis.com/css?family=Raleway:300' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" type="text/css" href="hexagons.css">
        <script src="jquery-3.2.1.min.js"></script>
        <script type="text/javascript">
//            function disp(){
//                document.getElementById('hexGrid').style.display = 'none';
//            }
        </script>
    </head>
    <body>
   <iframe name="display" id="display_template"></iframe>

    <ul id="hexGrid">
        <?php
        foreach ($dirs as $link) {
            if ($link != 'assets') {
            echo '
            <li class="hex">
                <div class="hexIn">
                    <a class="hexLink" href="'.$linkArray[$link].'" onclick="disp(); return false;" target="display" >
                        <img src="assets/dir.png" alt="'.$link.'" />
                        <h1>' . $link . '</h1>
                        <p>Redirect to template</p>
                    </a>
                </div>
            </li>
            ';
            }
        }
        ?>
    </ul>
    </body>

我想在链接的 onClick 上实现这一点,#hexGrid 将显示样式更改为无,同时 iframe 将加载一些内容。

当 JS 被评论时,点击时,iframe 会正确加载选定的内容,但是当 JS 处于活动状态时,它只是隐藏 #hexGrid 而不会将内容加载到 iframe 中。

知道出了什么问题吗? :)

【问题讨论】:

  • 忽略你已经展示了 JS ...
  • 所以您是说注释掉 JS 时 iframe 不加载?
  • 是的,我不知道为什么会这样
  • 所以它正在加载一个空白页面或您收到控制台错误?
  • 它停留在同一页面,只是隐藏那个#hexGrid。控制台说,加载 favicon.ico 时出现问题。没有别的了。

标签: javascript jquery html css iframe


【解决方案1】:

解决方法发现应该有 onclick="disp(); return true;"而是 onclick="disp(); return false;"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 2011-06-22
    相关资源
    最近更新 更多