我正在使用Rails3並安裝了最新的jQuery插件。我試圖弄清楚字符。計數功能從下面的這段代碼開始工作,但沒有成功。任何幫助,將不勝感激??Rails3和jQuery - 綁定這個javascript
文章/ _form.html.erb
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :body %><br />
<%= f.text_area :body id=testTextarea2 %>
</div>
<div class="field">
<%= f.label :tag_names, "Tags" %> <br />
<%= f.text_field :tag_names %>
</div>
佈局/ application.html.erb
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>myblog.com</title>
<%= stylesheet_link_tag 'scaffold' %>
<%= stylesheet_link_tag 'screen', :media => 'screen' %>
<%= stylesheet_link_tag 'print', :media => 'print' %>
<%= javascript_include_tag :defaults, "jquery.js", "counter.js", "rails.validations" %>
<%= csrf_meta_tag %>
<script src="/javascripts/jquery.textareaCounter.plugin.js" type="text/javascript"></script>
<script type="text/javascript">
var info;
$(document).ready(function() {
var options = {
'maxCharacterSize': -2,
'originalStyle': 'originalTextareaInfo',
'warningStyle' : 'warningTextareaInfo',
'warningNumber': 40
};
$('#testTextarea').textareaCount(options);
var options2 = {
'maxCharacterSize': 200,
'originalStyle': 'originalTextareaInfo',
'warningStyle' : 'warningTextareaInfo',
'warningNumber': 40,
'displayFormat' : '#input/#max | #words words'
};
$('#testTextarea2').textareaCount(options2);
var options3 = {
'maxCharacterSize': 200,
'originalStyle': 'originalTextareaInfo',
'warningStyle' : 'warningTextareaInfo',
'warningNumber': 40,
'displayFormat' : '#left Characters Left/#max'
};
$('#testTextarea3').textareaCount(options3, function(data)
{
$('#showData').html(data.input + " characters input. <br />" + data.left + " characters left. <br />" + data.max + " max characters. <br />" + data.words + " words input.");
});
});
</script>
SyntaxError in Articles#new
Showing /Users/blog/app/views/articles/_form.html.erb where line #23 raised:
compile error
/Users/blog/app/views/articles/_form.html.erb:23: syntax error, unexpected tIDENTIFIER, expecting ')'
...append= (f.text_area :body id="testTextarea2");@output_buf...
^
Extracted source (around line #23):
20:
21: <div class="field">
22: <%= f.label :body %><br />
23: <%= f.text_area :body id="testTextarea2" %>
24: </div>
25:
乾杯! (...öhhrm...賞金似乎仍然開放。) – polarblau 2011-05-30 13:37:23