Jquery:railscast 114,警报不显示,这是因为它是咖啡脚本

Jquery: railscast 114, alert not showing, is this because it's coffeescript?

本文关键字:是因为 脚本 咖啡 显示 railscast Jquery      更新时间:2023-09-26

我正在按照 railscast 教程 #114 进行无休止滚动,但我不使用 coffeescript。提供的 JavaScript 在调用警报时不起作用。这里有什么问题?谢谢。

$(document).ready(function(){
    $(window).scroll ->
      if $(window).scrollTop() > $(document).height() - $(window).height() - 50
        alert "near bottom"
 });

http://jsfiddle.net/fskx4jyr/

如果这是一个咖啡脚本问题,那么这段代码将如何用于在jquery中工作?

jQuery ->
  if $('.pagination').length
    $(window).scroll ->
      url = $('.pagination .next_page').attr('href')
      if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
        $('.pagination').text("Fetching more products...")
        $.getScript(url)
    $(window).scroll()
我已经

弄清楚了您的代码中的错误,请尝试运行此代码

$(document).ready(function(){
    $(window).scroll(function(){
      if ($(window).scrollTop() > ($(document).height() - $(window).height() - 50))
      {
         alert("near bottom");
      }
     });
 });

你的jquery函数中有语法错误。希望这对:)有所帮助

你可以在这里检查相同的