gpt4 book ai didi

jquery - 正确执行toggle()?

转载 作者:行者123 更新时间:2023-12-01 02:31:01 25 4
gpt4 key购买 nike

请有人告诉我为什么toggle()函数不起作用?我希望这不仅仅是一个简单的语法问题,而是有一个更技术性的原因,这不起作用。

http://jsfiddle.net/LEusd/

JS

$('a').click(function(){
console.log('Clicked...');
$('#login-form').toggle(function(){
console.log('Show...');
$(this).show();
}, function(){
console.log('Hide...');
$(this).hide();
});
});

HTML

<a href="#" title="">Link</a>
<div id="login-form"></div>

CSS

#login-form {
border:1px dashed red;
display: none;
height: 100px;
width: 100px;
}

最佳答案

简单

$('a').click(function(){
console.log('Clicked...');
$('#login-form').toggle();
});

编辑:(凯文的精彩评论)

The "click" version of .toggle was removed in 1.9, it no longer can be used to bind click events. In most cases it's usage can be replaced with a single click event and a toggle method such as toggle, toggleClass, etc

Working Fiddle

关于jquery - 正确执行toggle()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17283407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com