2015-08-13 47 views
0

我找不到问题。这是说:Codecademy - 互动网站:禁用按钮2

糟糕,再试一次。请记住,在发布新消息后禁用发布按钮

更新:事实证明Codecademy上有一个小错误,我重新提交了代码并且它工作正常。

var main = function() { 
    $('.btn').click(function() { 
     var post = $('.status-box').val(); 
     $('<li>').text(post).prependTo('.posts'); 
     $('.status-box').val(''); 
     $('.counter').text('140'); 
     $('.btn').addClass('disabled'); 
    }); 

    $('.status-box').keyup(function() { 
     var postLength = $(this).val().length; 
     var charactersLeft = 140 - postLength; 
     $('.counter').text(charactersLeft); 

     if(charactersLeft < 0) { 
      $('.btn').addClass('disabled'); 
     } 
     else if(charactersLeft == 140) { 
      $('.btn').addClass('disabled'); 
     } 
     else { 
      $('.btn').removeClass('disabled'); 
     } 
    }); 
      $('.btn').addClass('disabled'); 

      $(document).ready(main); 
      } 
+2

'$ addClass(' 禁用 ')丙'的'(' 残疾人',真正的')。 btn'点击处理程序 – Tushar

+1

您能否提供上述练习的codecademy链接? – WisdmLabs

+0

当然。 https://www.codecademy.com/courses/web-beginner-en-hk5qh/0/8?content_from=make-an-interactive-website%3Ajquery-dom-manipulation – user5220317

回答

0

Here是一个例子:

$('.btn').click(function() {$(this).attr("disabled", true);}) 
0

我想你忘记关闭功能括号。最后一行后应该有一个右括号和分号};这样的:( 'BTN ')

var main = function() { 
    $('.btn').click(function() { 
     var post = $('.status-box').val(); 
     $('<li>').text(post).prependTo('.posts'); 
     $('.status-box').val(''); 
     $('.counter').text('140'); 
     $('.btn').addClass('disabled'); 
    }); 

    $('.status-box').keyup(function() { 
     var postLength = $(this).val().length; 
     var charactersLeft = 140 - postLength; 
     $('.counter').text(charactersLeft); 

     if(charactersLeft < 0) { 
      $('.btn').addClass('disabled'); 
     } 
     else if(charactersLeft == 140) { 
      $('.btn').addClass('disabled'); 
     } 
     else { 
      $('.btn').removeClass('disabled'); 
     } 
    }); 
}; 
+1

嗯..我没有忘记,我认为我没有在第一时间粘贴整个代码。我编辑了我的代码。另外,谢谢:) – user5220317