我的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
可以设置iframe的src属性。
function goto(url) {
document.getElementById("contentFrame").src = url;
}
:
你的PHP代码有错误。用下面的代码改变A标签:
onclick='"goto('imagegallery.php?category=".$myRow['productcategory']."')'"
注意斜杠…如果产品类别中有斜杠,则必须使用addslashes PHP函数添加一些反斜杠,或者更好的方法是使用PHP rawurlencode以URL格式编码所有字符。