gpt4 book ai didi

javascript - 使用 Coffeescript/JQuery 进行模板化和转义

转载 作者:行者123 更新时间:2023-12-03 11:10:27 26 4
gpt4 key购买 nike

我编写的一些 CoffeeScript 中的以下选择器一直给我带来麻烦。

$('span[data-id="#{cat_id}"]').attr('class', 'dropdown-toggle icon-button fold')

编译并运行时,引号内的文本变为:

span[data-id="#{cat_id}"]

我尝试将选择器外部的单引号更改为双引号,但随后出现运行时错误:

ExecJS::应用程序中的运行时错误#handle_404显示/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', '图标切换折叠')

我尝试过连接"/'"+ 选择器+ "/'" ,但这也不起作用。

最佳答案

$("span[data-id=#{cat_id}]")

我猜内部引号是不必要的,但外部仍然需要双引号以允许解释 #{}

关于javascript - 使用 Coffeescript/JQuery 进行模板化和转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27622371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com