【发布时间】:2017-07-11 07:57:45
【问题描述】:
请原谅我有一个非常基本的问题,因为我仍在使用 Jquery。 我正在尝试在单击此 .html 页面中的任何图形元素时加载另一个 .html 页面,但脚本标签未按预期工作任何人都可以帮助以下 js
html代码:
$(document).ready(function(){
$("figure").click(function(){
$(this).load("singlevideo.html");
});
});
* {
padding:0px;
margin:0px;
}
body {
margin:0;
padding:0;
height:100%;
}
header {
background: green;
color: white;
padding: 8px 0px 6px 40px;
height: 50px;
}
.navbar.navbar-inverse.navbar-fixed-top {
background-color: green; /* fallback color, place your own */
font-weight: 400;
color: white;
text-decoration: none;
}
header h1 {
display: inline;
font-family: 'Oswald',sans-serif;
font-weight: 400;
font-size: 32px;
float: left;
margin-top: 0px;
margin-right: 10px;
}
nav ul{
display: inline;
padding: 0px;
float: left;
}
nav ul li{
display: inline-block;
list-style-type:none;
color: white;
float: left;
margin-left: 15px;
}
nav ul li a{
color: white;
text-decoration: none;
}
#nav {
font-family: 'Montserrat', sans-serif;
position: fixed;
}
.homered{
background-color: red;
padding: 30px 10px 30px 10px;
}
.homeblack:hover{
background-color: blue;
padding: 30px 10px 30px 10px;
}
div{
width:250px;
height:666px;
background:#1A8DA9;
}
div a{
text-decoration:none;
color:white;
padding:20px;
padding-right:100px
}
div ul li{
list-style-type:none;
display:block;
padding :15px;
border-bottom:1px solid #236D7F;
}
div ul li :hover{
background:#4097AD;
transition:linear all 0.40s;
margin-left:10px;
}
div ul li a:hover{
color:black;
}
#navBar {
float: left;
position: fixed;
}
#nav {
float: right;
}
#maincontent{
width: 80%;
height: auto;
outline: 1px solid;
position: absolute;
right: 0;
background: white;
}
figure {
display: inline-block;
}
}
figure figcaption {
text-align: center;
}
iframe:focus {
outline: none;
}
iframe[seamless] {
display: block;
}
.footer {
position:fixed;
left:0px;
bottom:0px;
height:30px;
width:100%;
background:green;
text-align: center;
}
<!DOCTYPE HTML>
<html lang = "en">
<head>
<title>Videos</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="videos.css">
</head>
<body>
<header>
<nav class="navbar navbar-inverse navbar-fixed-top">
<h1> Main logo </h1>
<ul id="nav">
<li><a class="homeblack" href="index.html">Home</a></li>
<li><a class="homered" href="videos.html">Videos</a></li>
<li><a class="homeblack" href="news.html">News</a></li>
<li><a class="homeblack" href="contactus.html">Contactus</a></li>
</ul>
</nav>
</header>
<div id="navBar">
<ul>
<li><a href="#">video </a></li>
<li><a href="#">video </a></li>
<li><a href="#">video </a></li>
<li><a href="#">video </a></li>
</ul>
</div>
<div id="maincontent">
<figure id="1">
<iframe width="300" height="240" src="https://www.youtube.com/embed/VORxzZazSnc" frameborder="0" allowfullscreen></iframe>
<figcaption> Trailer </figcaption>
</figure>
<figure id="2">
<iframe width="300" height="240" src="https://www.youtube.com/embed/VORxzZazSnc" frameborder="0" allowfullscreen></iframe>
<figcaption> Trailer</figcaption>
</figure>
<figure id="3">
<iframe width="300" height="240" src="https://www.youtube.com/embed/_fL4RuPcDw4" frameborder="0" allowfullscreen></iframe>
<figcaption> trailer </figcaption>
</figure>
<figure id="4">
<iframe width="300" height="240" src="https://www.youtube.com/embed/7yxNzMhXSr4" frameborder="0" allowfullscreen></iframe>
<figcaption> trailer </figcaption>
</figure>
<figure id="5">
<iframe width="300" height="240" src="https://www.youtube.com/embed/ljuBWvzZtyc" frameborder="0" allowfullscreen></iframe>
<figcaption> trailer</figcaption>
</figure>
<figure id="6">
<iframe width="300" height="240" src="https://www.youtube.com/embed/2ZBHa9gIOp4" frameborder="0" allowfullscreen></iframe>
<figcaption>Trailer</figcaption>
</figure>
</div>
<div class="footer">
<p style="color:white; font-size:20px; font-weight:bold;">Copyright © Education Students</p>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
【问题讨论】:
-
检查您是否收到
click事件。有可能,您单击iFrame并且事件被困在它的 DOM 树中。 -
@Justinas 这不是问题
-
load函数进行 Ajax 调用以检索页面而不是在浏览器中加载页面。你应该看看第一条评论。
标签: javascript jquery html css