我在这里使用了以下脚本:http://8wayrun.com/wiki/algol/
XenForo.register('.ToggleContents', 'XenForo.ToggleContents');
XenForo.ToggleContents = function($toc)
{
var hideText = 'hide';
var showText = 'show';
var isVisible = true;
$toc.ready(function() {
$toc.find(':first').append('<span class="toggle">(<a href="#">'+hideText+'</a>)</span>');
});
$toc.find('.toggle:first').click(function(e)
{
e.preventDefault();
if (isVisible = !isVisible)
{
$toc.find('.toggle a:first').html(hideText);
$toc.find('.contents:first').slideDown();
}
else
{
$toc.find('.toggle a:first').html(showText);
$toc.find('.contents:first').slideUp();
}
});
}它的作用非常简单。它做的第一件事是将一个<span class="toggle">hide</a>链接附加到任何带有".ToggleContents“类的div上……这个很好用。
它做的下一件事是采用它刚刚创建的链接,阻止默认函数,并将其改为隐藏/显示链接。这在jQuery 1.4.x中运行得很好。然而,在jQuery 1.5.x中,它根本不起作用。e.preventDefault()永远不会运行...
这告诉我.find('.toggle:first')不能在1.5.x中工作。有人知道我现在应该用什么吗?
发布于 2011-11-25 01:15:51
我想通了..。在1.5.x中这是必需的,但在1.4.x中不是...非常奇怪。
我所做的是将$toc.find('.toggle:first').click(function(e)移到$toc.ready(function()中,现在一切都运行得很好。
https://stackoverflow.com/questions/8260280
复制相似问题