获取未定义引导程序的'无法读取属性'offsetwidth' [英] Getting 'cannot read property 'offsetwidth' of undefined bootstrap
问题描述
我得到了 offsetwidth
undefined尽管添加了活动类,并且在我的js函数之上定义了我的jquery。我必须使用旋转木马来完成我的工作,我尝试了一个模拟练习。我的第一个活动图像正在显示,然后在我单击下一步后,我在控制台中收到此错误,图像没有滑动。
I get the offsetwidth
undefined in spite of adding active class and also defining my jquery just above my js function. I have to use carousel for my work and I tried a mock one for practice. My first active image is displaying and after I click next I get this error in console and the images are not sliding.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title>mycooking</title>
</head>
<body>
<!--indicatiors-->
<div class="container">
<div class="row-fluid">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!--wrapper for slides-->
<div class="carousel-inner" role="listbox">
<div class="item-active">
<img class="first-slide" src="/img/dosa.jpg" alt="dosa" />
</div>
<div class="item">
<img class="second-slide" src="/img/idli.jpg" alt="idli" />
</div>
<div class="item">
<img class="third-slide" src="img/vada.jpg" alt="vada" />
</div>
</div>
<!--Left and right controls-->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
$("#myCarousel").carousel({
interval: 1200
})
});
</script>
</body>
</html>
推荐答案
在HTML中更改此行:
Change this line in your HTML:
<div class="item-active">
到
<div class="item active">
该连字符不应存在。如果您需要 item-active
类,请在这两个之后添加,例如< div class =item active item-active>
。 item
和 active
是bootstrap用来运行轮播的类。如果没有第一张幻灯片,你就会收到错误。
That hyphen shouldn't be there. If you need an item-active
class, add it after those two, like <div class="item active item-active">
. item
and active
are classes bootstrap uses to run the carousel. Without them on that first slide, you'll get that error.
HTH,
-Ted
HTH, -Ted
这篇关于获取未定义引导程序的'无法读取属性'offsetwidth'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!