【发布时间】:2015-09-08 08:00:50
【问题描述】:
我的网站上的 javascript 有问题:
感谢您的帮助,我的 .mouseenter 和 .mouseleave() 已解决,但我的 .accordion() 仍然无法正常工作。有什么想法吗?
这是我的代码:
HTML:
<!DOCTYPE html>
<head>
<!--Accordion is not working, mouseenter is only working in first product, header is not all the way to the left-->
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap-theme.css" />
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="js/bootstrap.js" />
<link rel="stylesheet" href="js/carousel.js" />
<link rel="stylesheet" type="text/css" href="shopping.css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery- ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<header>
<h4><mark>Student Project #5 H.B.</mark></h4></br>
<h2>Premium Computer Supplies!</h2>
</header>
<body>
<!----------------------------------------------------------------->
<div class="row" id="row">
<!--<div class="col-sm-3">-->
<!--Insert picture-->
<img src="surface3.jpg" alt="Microsoft Surface">
<!--Accordion heading-->
<div class="accordion">
<h4>Microsoft Surface Pro 3</h4>
<!--Description and price-->
<div>
<p>Insert description for the product here</p>
<p>Starting at $999!</p>
</div>
</div>
</div>
</div>
<!----------------------------------------------------------------->
<div class="row" id="row">
<!--<div class="col-sm-3">-->
<!--Insert picture-->
<img src="surface3cover.jpg" alt="Microsoft Surface Type Cover">
<!--Accordion heading-->
<div id="accordion">
<h4>Microsoft Surface Pro 3 Typer Cover</h4>
<!--Description and price-->
<div>
<p>Insert description for the product here</p>
<p>Starting at $129!</p>
</div>
</div>
</div>
</div>
<!----------------------------------------------------------------->
<div class="row" id="row">
<!--<div class="col-sm-3">-->
<!--Insert picture-->
<img src="mabook.jpg" alt="Apple Macbook Pro Retina">
<!--Accordion heading-->
<div id="accordion">
<h4>Macbook Pro Retina Display</h4>
<!--Description and price-->
<div>
<p>Insert description for the product here</p>
<p>Starting at $999!</p>
</div>
</div>
</div>
</div>
<!----------------------------------------------------------------->
<div class="row" id="row">
<!--<div class="col-sm-3">-->
<!--Insert picture-->
<img src="superdrive.jpg" alt="Apple SurperDrive">
<!--Accordion heading-->
<div id="accordion">
<h4>Apple SuperDrive</h4>
<!--Description and price-->
<div>
<p>Insert description for the product here</p>
<p>Starting at $79!</p>
</div>
</div>
</div>
</div>
<!----------------------------------------------------------------->
<div class="row" id="row">
<!--<div class="col-sm-3">-->
<!--Insert picture-->
<img src="case1.jpg" alt="Laptop Case">
<!--Accordion heading-->
<div id="accordion">
<h4>Laptop Case</h4>
<!--Description and price-->
<div>
<p>Insert description for the product here</p>
<p>Starting at $39!</p>
</div>
</div>
</div>
</div>
<!----------------------------------------------------------------->
<script>
$(function() {
$( ".accordion" ).accordion();
});
$( ".row" ).mouseenter(function() {
$(this).animate({ fontSize : 14 });
});
$( ".row" ).mouseleave(function() {
$(this).animate({ fontSize : 13 });
});
</script>
</body>
CSS:
img {
width:300px;
height:200px;
}
header{
background-color: crimson;
color:darkblue;
padding-left: 0;/*why is this not working*/
width:100%
}
body{
width:80%;
background-color: lightgray;
font-size: 13;
padding-left: 5%
}
#row{
background-color: white;
width:30%;
padding-left: 5%;
}
【问题讨论】:
-
在你的css中,在
padding-left:和0之间放一个空格 -
因为每个id都必须唯一,jquery只抓取第一个。您应该为它们添加一个类并引用它。
-
ids 在文档中必须是唯一的。 -
当 Javascript 停止工作时,十分之九,你有一个无效的 DOM。确保您的标签打开和关闭均匀,您有唯一的 ID 等。
-
谢谢,我添加了这个空格并且填充保持不变?
标签: javascript jquery css html