有jQuery公平知识的人可以帮助我吗?

时间:2012-12-29 09:37:03

标签: jquery

我无法对这里发生的事情做出一些合乎逻辑的判断,有人可以帮助我吗?

// heynow.js
$(document).ready(function() {

  // on the checkbox disable it right away
  $('#agree').attr('disabled', 'disabled');

  //on the terms box add a scroll function
  $('#terms').scroll(function() {  

    // textareheight equals scrollheight   not accurate
    var textareaheight = $(this).[0].scrollHeight;

    // scrollheight equals scrollheight – the innerheight  which is more accurate and dynamic
    var scrollheight = textareaheight - $(this).innerHeight();

    // scrolltop equals  scrolltop returning where are you
    var scrolltop = $(this).scrollTop();

    // if where you at equals the total height
    if (scrolltop == scrollheight) {

      // then enable the checkbox
      $('#agree').removeAttr('disabled');
    }
  });
});

<!-- html file -->
<p><textarea id="terms">lots of text for a scroll avail</textarea></p>
<p><input id="agree" type="checkbox" /> I Agree</p>

1 个答案:

答案 0 :(得分:6)

这很简单。它会禁用复选框并保持这种状态,直到您向下滚动到内容的末尾。这没什么特别的:)你可以在接受许可之前阅读许可证的页面上看到它。