如何访问之前在 javascript 中定义的 opal-ruby 代码中的变量?例如在下面的代码中如何修复蛋白石文件。
index.html.erb
...
<script>
var test = "hi"
</script>
...
index.js.opal
Document.ready? do
puts test
end
最佳答案
Opal 允许您使用反引号输出任何您不希望 Opal 解释的原始 JavaScript,因此这将输出包含“hi”的 test
字符串:
Document.ready? do
puts `test`
end
关于javascript - 我如何在 Opal-rails 中打印在 Javascript 中定义的变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13332579/