[英]JQuery : hover doesn't work
I have a little problem trying to use JQuery.我在尝试使用 JQuery 时遇到了一个小问题。
Here's the code I would like to make work on my page :这是我想在我的页面上工作的代码:
http://jsfiddle.net/ktz0f6st/ http://jsfiddle.net/ktz0f6st/
But it doesn't work on my page :但它在我的页面上不起作用:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
$(document).ready(function() {
$('.timeline').hover(function() {
$(this).css('background-color', 'blue');
}, function() {
$(this).css('background-color', 'cyan');
});
});
</script>
<section id="eduandwork" style="top:20%; bottom:20%; height:100%; width:100%; text-align:center;">
<div class="container hidden-xs">
<ul class="timeline">
<li class="timeline-inverted">
<div class="timeline-panel">
<div class="timeline-heading">
<h5 class="timeline-title"><br><br>IT MANAGEMENT BACHELOR</h5>
</div>
<div class="timeline-body">
<p>2014 - 2019</p>
</div>
</div>
</li>
</ul>
</div>
</section>
This is my code.这是我的代码。
EDIT : By saying it doesn't work, I mean when I hover the element, it doesn't change anything.编辑:说它不起作用,我的意思是当我悬停元素时,它不会改变任何东西。
Your script tag should look like those below: Here is your answer:您的脚本标签应如下所示: 这是您的答案:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.timeline').hover(function() {
$(this).css('background-color', 'blue');
}, function() {
$(this).css('background-color', 'cyan');
});
});
</script>
<section id="eduandwork" style="top:20%; bottom:20%; height:100%; width:100%; text-align:center;">
<div class="container hidden-xs">
<ul class="timeline">
<li class="timeline-inverted">
<div class="timeline-panel">
<div class="timeline-heading">
<h5 class="timeline-title"><br><br>IT MANAGEMENT BACHELOR</h5>
</div>
<div class="timeline-body">
<p>2014 - 2019</p>
</div>
</div>
</li>
</ul>
</div>
</section>
At the end of your Jquery call add in an end script tag, then start a new one.在您的 Jquery 调用结束时添加一个结束脚本标记,然后开始一个新的标记。
In your initial script call you specify a source "src='blah'".在您的初始脚本调用中,您指定一个源“src='blah'”。 If you run your code inline on the page in a second script or in your page's files it will run successfully.
如果您在页面上的第二个脚本或页面文件中内联运行代码,它将成功运行。
If you call jquery first, then run a second script with your code, your hover works just fine.如果你先调用 jquery,然后用你的代码运行第二个脚本,你的悬停工作就好了。
http://jsfiddle.net/mPawlak/heczLkxd/ http://jsfiddle.net/mPawlak/heczLkxd/
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script><script>
$(document).ready(function() {
$('.timeline').hover(function() {
$(this).css('background-color', 'blue');
}, function() {
$(this).css('background-color', 'cyan');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.