1
我有以下的JavaScript。例如,当我加载JavaScript时,触发器会触发console.log('test')
。我希望当我点击一个带有类登录的按钮时它会被触发。我究竟做错了什么?为什么我的函数在页面加载时触发,我该怎么办?
$(document).ready(function() {
switchImage(5000, '#top .images');
switchImage(5000, '#top .feature-text');
$('.login input').focus(function(){
$('.login .hidden').removeClass("hidden");
$('.login [type=text]').removeClass("span2").addClass("span3");
});
$('.loginbutton').click(login());
});
function login(){
event.preventDefault();
console.log('test')
}
function switchImage(wait, element){
//Fades out first element and put's it in the bottom of the stack
$(element+'>*:first-child').delay(wait).fadeOut('slow', function() {
//fade in imag2
$(element+'>*:nth-child(2)').fadeIn('slow');
$(element+'>*:first-child').appendTo(element);
switchImage(wait, element);
});
}