2

Please could someone advise why the toggle() function is not working? Im hoping theres more to this than a simple syntax issue, rather there is a more technical reason this isnt working.

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;
}
4

1 回答 1

7

简单地

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

编辑:(凯文的可怕评论

.toggle 的“点击”版本在 1.9 中被移除,它不再可以用于绑定点击事件。在大多数情况下,它的用法可以替换为单击事件和切换方法,例如切换、切换类等

工作小提琴

于 2013-06-24T19:22:54.767 回答