简体   繁体   English

为什么我的JQuery代码不起作用?

[英]Why doesn't my JQuery code work?

I have some code that doesn't seem to work. 我有一些似乎无效的代码。 I would think that this should give me an alert the instant I scroll, but no. 我认为这应该在我滚动时立即提醒我,但不会。 Could anyone tell me what is wrong with it? 谁能告诉我这是怎么回事?

$(document).ready(function(){
    $(document).scroll(function(){
        alert("hi!");
    )};
});

Syntax error with bracket line 4 - correct code : 括号第4行的语法错误-正确的代码:

$(document).ready(function(){
    $(document).scroll(function(){
        alert("hi!");
    });
});

http://jsfiddle.net/SLQj2/ http://jsfiddle.net/SLQj2/

just typo: )}; 只是拼写错误:)}; should be }); 应该 });

Just tested this and works fine. 刚刚测试了一下,效果很好。 Any errors in your console? 您的控制台有任何错误吗?

$(document).on( 'scroll', function(){ console.log('Event Fired'); });

$(document).ready(function(){
    $(document).scroll(function(){
        alert("hi!");
    });<---- please pay attention here!
});

you need a js editer(good editer can help you avoiding simple mistake) 您需要一个js编辑器(好的编辑器可以帮助您避免简单的错误)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM