【发布时间】:2014-12-23 22:40:24
【问题描述】:
我写的一些coffeescript中的这个选择器一直给我带来麻烦。
$('span[data-id="#{cat_id}"]').attr('class', 'dropdown-toggle icon-button fold')
编译运行后,引号内的文字变为:
span[data-id="#{cat_id}"]
我尝试将选择器外部的单引号更改为双引号,但随后出现运行时错误:
应用程序#handle_404 中的 ExecJS::RuntimeError 显示 /Users/michaeldiscenza/Documents/RUN_source_repos/run_portal/app/views/layouts/application.html.erb 其中第 33 行提出: [stdin]:222:88: 错误:不匹配的 OUTDENT $('span[data-id="#{cat_id}"]').children().attr('class', 'icon toggle collapse')
我尝试过 concatenating"/'" + selector + "/'" ,但也没有用。
【问题讨论】:
-
试过
$('span[data-id=#{cat_id}]')(属性选择器值周围没有双引号)? -
我认为单引号意味着#{}不会被解释,所以我最终得到
Uncaught Error: Syntax error, unrecognized expression: span[data-id=#{cat_id}] -
字符串插值不会发生在单引号字符串中。
标签: javascript jquery coffeescript