rubyonrails3-Rails3和jQuery-绑定这个javascript



Am使用Rails3并安装了最新的jQuery插件。我正试图得到炭。count函数使用下面的代码,但没有任何成功。有什么需要帮忙的吗??

articles/_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>

layouts/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:  

您看到的错误与jQuery或JS无关。text_area帮助程序需要一个属性散列——这应该可以消除错误:

f.text_area :body, :id => "testTextarea2"

我希望看到下面的html在某个地方生成,它在哪里——你没有显示代码吗?

 <textarea id="testTextarea" cols="60" rows="10" ></textarea>
 <div class="originalTextareaInfo warningTextareaInfo">
 <textarea id="testTextarea2" cols="60" rows="10" ></textarea>
 <div class="originalTextareaInfo warningTextareaInfo">
 <textarea id="testTextarea3" cols="60" rows="10" ></textarea>
 <div class="originalTextareaInfo warningTextareaInfo">
 <div id="showData"></div>

相关内容

  • 没有找到相关文章

最新更新