[英]JQuery Toggle with CSS
I have replicated a toggle functionality from this site: http://www.williamsprofessionalpainting.com/FAQ.php 我已经从以下站点复制了切换功能: http : //www.williamsprofessionalpainting.com/FAQ.php
Here is the updated version which renders the basic toggle function with minimum CSS: 这是更新的版本,使用最少的CSS呈现了基本的切换功能:
http://jsfiddle.net/NinjaSk8ter/yXNmx/ http://jsfiddle.net/NinjaSk8ter/yXNmx/
Your code is working fine, but jsFiddle is wrapping it in a function. 您的代码工作正常,但是jsFiddle将其包装在一个函数中。 In other words, it ends up looking something like: 换句话说,它最终看起来像:
window.onload = function() {
function ToggleFAQ(Ans) {
...
}
};
The function is defined within the onload handler, so when your onclick tries to call it, it doesn't exist. 该函数在onload处理函数中定义,因此当您的onclick尝试调用它时,该函数不存在。
If you change the drop-down on the top-left of your fiddle to "no wrap", it all works fine. 如果将小提琴左上角的下拉菜单更改为“ no wrap”,则一切正常。 See this modified version. 请参阅此修改版本。
On your JSFiddle - if you change the wrap method to "no wrap(head)" and it simply works. 在您的JSFiddle上-如果将wrap方法更改为“ no wrap(head)”,它就可以正常工作。
Alternatively - you can declare the function as a global var: 或者,您可以将函数声明为全局变量:
ToggleFAQ = function (Ans)
{
//..
}
what renders as 呈现为
jQuery(document).ready(function(){
//when defined like this - ToggleFAQ will still be visible when the
//"ready" event finishes.
ToggleFAQ = function (Ans)
{
//..
}
}
the wrap you selected puts your code in a function passed to jQuery's "dom-ready" event - and that's a closure that once is executed - all local variables are "vaporized". 选择的换行将代码放入传递给jQuery的“ dom-ready”事件的函数中-这是一个一旦执行便关闭的闭包-所有局部变量均“蒸发”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.