切换jQuery,在jsfiddle上工作,但不在我的网站上吗? [英] toggling with jquery, working on jsfiddle but not my site?
本文介绍了切换jQuery,在jsfiddle上工作,但不在我的网站上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我的切换功能在此jsfiddle上有效,但在我的网站上不起作用?
why is my toggle function working on this jsfiddle but not my site?
这是JS小提琴: http://jsfiddle.net/timur/bMfdD/4/ 这是网站: http://www.blindsdetroit.com/testing
Here is the JS Fiddle: http://jsfiddle.net/timur/bMfdD/4/ Here is the website: http://www.blindsdetroit.com/testing
<a id="clickMe" href="#">Type of Worker</a>
<div id="clickEvent" class="hide">
<ul>
<li>Rivermen</li>
<li>Boatmen</li>
<li>stuff</li>
</ul>
</div>
这是jQuery
$('#clickMe').click(function() {
$("#clickEvent").fadeToggle("slow");
});
这是CSS
.hide { display:none; }
推荐答案
将代码放入文档就绪处理程序中
Put your code inside document ready handler
$(function(){
$('#clickMe').click(function() {
$("#clickEvent").fadeToggle("slow");
});
});
您不必在小提琴中编写就绪的处理程序,因为您的代码会自动用document.ready包装(它们是一个选择选项)
You don't have to write ready handler in your fiddle as your code is automatically wrapped with document.ready (their is an option to choose from)
<---
在文档准备就绪时执行代码
<---
your code is executed when document is ready
这篇关于切换jQuery,在jsfiddle上工作,但不在我的网站上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文