我想在我的HAML标记中添加一个日期选择器。 我从这个问题开始,尝试了两种方法来添加脚本:
%h3 Please enter the following information: = form('/some_path', :post) = input(:date, :start_date, class: "formbox") = input(:date, :end_date, class: "formbox") = submit('Submit', class: "button") %script(type="text/javascript") $(function() {$( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});});和
:javascript $(function() { $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'}); });这一个最终是正确的,问题是形式的一部分。
两者都产生错误syntax error, unexpected keyword_ensure, expecting end-of-input在线syntax error, unexpected keyword_ensure, expecting end-of-input :javascript或%script(type="text/javascript")
如何解决这个问题并添加脚本?
I want to add a datepicker to my HAML markup. I started with that question and tried 2 approaches to add an script:
%h3 Please enter the following information: = form('/some_path', :post) = input(:date, :start_date, class: "formbox") = input(:date, :end_date, class: "formbox") = submit('Submit', class: "button") %script(type="text/javascript") $(function() {$( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});});and
:javascript $(function() { $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'}); });This one was finally correct, problem was in form part.
Both produce an error syntax error, unexpected keyword_ensure, expecting end-of-input on line :javascript or %script(type="text/javascript")
How to fix that and add the script?
最满意答案
%script标签需要大括号; 在后一个示例中,需要=content_for标记:
%script{data:{'foo'=> 'bar'}, 'type'=> "text/javascript"} = content_for :javascripts do :javascript $(function() { $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'}); });%script tag expects curly brackets; in the latter example there is =content_for tag needed:
%script{data:{'foo'=> 'bar'}, 'type'=> "text/javascript"} = content_for :javascripts do :javascript $(function() { $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'}); });更多推荐
发布评论