【问题标题】:Dynamic navigation links with Mysql, Php and Javascript使用 Mysql、Php 和 Javascript 的动态导航链接
【发布时间】:2015-05-27 22:24:05
【问题描述】:

我的 Javascript 函数确实有效,但不适用于这段代码。

我显示了所有内容,但导航链接不会针对我的 iframe。

谁能解释我的代码有什么问题?

这是我的代码:

function goto(url) { 
           document.getElementById("contentFrame").contentWindow.location.replace(url);
           }
</script>

<title>SOLSTEN</title>
</head>    
<body>    
<div id="rubrik"><h1>SOLSTEN</h1></div>         
    <?php
$mysqli = new mysqli('localhost', 'root', '', 'solsten');
            $sql = "select distinct productcategory from products";
            $result = $mysqli->query($sql);
                    echo "<div id='menu'>";
    while($myRow = $result->fetch_array())
                    {
                        echo "<ul>";
                        echo "<li style='display: inline;'><a href='javascript:void(0)' onclick='goto('imagegallery.php?category=".$myRow['productcategory']."')'> <h4>".$myRow["productcategory"]."</h4></a> </li>";
                        echo "</ul>";

                        } 
                    echo "</div>";  
    ?>

</div> 
     <div class='content'   >

<iframe src="imagegallery.php?category=Armband" scrolling="no" height='100%' width='100%' marginwidth='0' marginheight='0' scrolling='auto' onload='' allowtransparency='false'   id="contentFrame"></iframe>"

</div>

我在这张图片上获得了我的导航链接的源代码。 >>http://test.mehmetakb.se/solsten1.jpg

【问题讨论】:

    标签: javascript php mysql dynamic navigation


    【解决方案1】:

    可以设置 iframe 的 src 属性。

    function goto(url) { 
               document.getElementById("contentFrame").src = url;
               }
    

    更新

    您的 PHP 代码中有错误。 使用此代码更改 A 标记:

    onclick=\"goto('imagegallery.php?category=".$myRow['productcategory']."')\"
    

    注意斜线。如果产品类别中有斜线,则必须使用 addlashes PHP 函数添加一些反斜线,或者更好的方法是使用 PHP rawurlencode 以将所有字符编码为 URL 格式。.

    【讨论】:

    • 我的 iframe 的 src="" 是我的 iframe 的默认内容。但是当我点击导航链接时,我会得到这样的源代码。 >>test.mehmetakb.se/solsten1.jpg
    猜你喜欢
    • 2017-01-15
    • 2012-06-25
    • 1970-01-01
    • 2023-03-08
    • 2010-10-08
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多