我有弹出新屏幕的JavaScript函数,我需要在Rails视图中使用它们。
这是/app/assets/signup.js
中的脚本:
<script type="text/javascript">
function popup() {
cuteLittleWindow = window.open("signup.html", "littleWindow", "location=no,width=320,height=200");
}
</script>
如何在/views/index.html.erb
中使用JavaScript函数?
答案 0 :(得分:0)
将以下代码放在关闭正文标记之前,如下所示:
<body>
<!-- Your body things -->
<script>
$(function(){
function popup(){
cuteLittleWindow = window.open("signup.html", "littleWindow", "location=no,width=320,height=200");
}
});
</script>
</body>
答案 1 :(得分:0)
使用Rails #####your view code
<script type="text/javascript">
$(document).ready(function(){
function popup(){
cuteLittleWindow = window.open("signup.html", "littleWindow", "location=no,width=320,height=200");
}
})//document ends
</script>
turbolinks
,您必须收听turbolinks:load
事件:$(document).on "turbolinks:load", ->
alert "page has loaded!"