javascript - Ruby On Rails - 如何在元素后生成 javascript include

标签 javascript jquery ruby-on-rails haml

我正在尝试在 javascript include 之后执行 = yield :javascript

所以我在 html 中有这样的东西:

<body>
<!-- my actual = yield :javascript of javascript calling my js codes -->
 <script type="text/javascript">//my-js-code</script>

<!-- javascript include tag that contains jQuery -->
<script type="text/javascript" src="path/to/jquery"></script>
</body>

所以在我的 index.html.haml 中,我的 javascript 产量需要放置在 jQuery 的这个包含之后,问题是我无权访问 jquery 的这个包含,我需要类似的东西this:“选择此 javascript 的产量并放在包含 和 id 的脚本标记后面,例如”

有人可以帮忙吗?

观察:我使用的是 Rails 4、Ruby 2 和 Haml

最佳答案

通常,您可以通过 require 等方式在 application.js 中订购 js 文件。

因此,如果您需要在加载其他 javascript 后加载一些 javascript,请将您的 js 代码拆分到不同的文件中,并按照您希望的顺序加载文件。

也许这个链接有帮助:http://guides.rubyonrails.org/asset_pipeline.html 有一节“2.2 Assets 组织”可能对您有用。

关于javascript - Ruby On Rails - 如何在元素后生成 javascript include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552594/

相关文章:

ruby-on-rails - 设计 API 身份验证

javascript - 使用 JavaScript 从 UIWebView 清除凭据

javascript - 使用 jQuery 创建 HTML 元素 : what’s the correct approach?

jQuery 解析 JSON URL

javascript - jQuery 函数不在条件循环中触发

ruby-on-rails - Test::Unit 应该相当于 RSpec should_receive

ruby-on-rails - 开始学习 Rails 源代码

javascript - 在 Javascript 中使用 CDATA block 内的变量?

javascript - Foreach 无法在 php 和 Jquery 中工作

javascript - 在 DIV 上拖放文本