我在这里看到的代码如下:
在鼠标悬停时,我在Chrome控制台中收到了“SyntaxError:Unexpected token ILLEGAL”的错误提示。我已经在控制台中删除了空格,这样就可以解决问题了。但是如何清除Ruby渲染中的空格呢?
我有一些像这样的代码
$(".someclass").hover(function(){
$(this).append("#{render "layouts/show_some_file", title: "some_file"}");
});
show_some_file.html.haml
文件由两个嵌套的基本div组成
在我的浏览器中,我得到:
$(".someclass").hover(function(){
$(this).append("<div>
<div>some text</div>
</div>
");
});
在鼠标悬停时,我在Chrome控制台中收到了“SyntaxError:Unexpected token ILLEGAL”的错误提示。我已经在控制台中删除了空格,这样就可以解决问题了。但是如何清除Ruby渲染中的空格呢?
<script id="some_id" type="text/template">#{render "layouts/show_some_file", title: "some_file"}</script>
。然后要获取其内容,您可以使用$(this).append($("#some_id").html());
。它有点像模板。您使用script
标记,但将其type
设置为不会导致其被执行的内容。由于script
标记在页面上永远不可见,因此您永远不会遇到视觉问题...与在div
内部执行此操作不同...然后HTML与页面的其余部分“分离”。 - Ian