我正在做Codeacademy JavaScript課程,我做得很好。直到現在,我一直能夠自己解決我的問題。我只是無法做到。關於語法錯誤的JavaScript? (codecedemy)
繼承人我的代碼 的JavaScript
var main = function() {
$('.btn').click(function() {
var post = $('.status-box').val();
$('<li>').text(post).prependTo('.posts')
$('.status-box').val(''),
});
$('.status-box').keyup(function() {
var postLength = $(this).val().length;
var charactersLeft = 140 - postLength;
$('.counter').text(charactersLeft);
});
}
$(document).ready(main);
HTML
<!doctype html>
<html>
<head>
<link href="http://s3.amazonaws.com/codecademy-content/courses/ltp2/css/bootstrap.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="container">
<form>
<div class="form-group">
<textarea class="form-control status-box" rows="2" placeholder="What's on your mind?"></textarea>
</div>
</form>
<div class="button-group pull-right">
<p class="counter">140</p>
<a href="#" class="btn btn-primary">Post</a>
</div>
<ul class="posts">
</ul>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="app.js"></script>
</body>
</html>
的JavaScript代碼是行不通的。它應該讓一個字符計算剩餘的文本框中剩餘的字符數量。問題是代碼無法正常工作。請記住我是初學者,所以在提出解決問題的方法時儘可能清楚。我認爲這個問題在JavaScript代碼的某個地方很小,但我無法找到它,因爲我對JavaScript的理解還不夠理想。謝謝!
您可能想要開始使用瀏覽器進行調試。它會幫助你找到這些小小的語法錯誤:) – 2014-10-07 09:00:30
我完全清楚網絡開發。昨天就開始了,但如果你想解釋一下broswer控制檯是什麼,id很高興能夠試用 – 2014-10-07 09:03:21
這與你對桌面應用程序進行編程是一樣的。它會記錄編譯或運行時錯誤,並導致您導致錯誤的行號,函數名等。你可以在這個鏈接上閱讀它。 https://developer.mozilla.org/zh-CN/docs/Tools/Browser_Console – 2014-10-07 09:06:38