将javascript添加到HAML标记错误(Adding javascript to HAML markup error)

编程入门 行业动态 更新时间:2024-10-26 21:21:21
将javascript添加到HAML标记错误(Adding javascript to HAML markup error)

我想在我的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'}); });

更多推荐

本文发布于:2023-07-25 22:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   错误   HAML   javascript   markup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!