我有一个与id="<%= p.id %>"
(在模式中的帖子的ID)的模态。我想在模式打开的时候使用模式的内容(并且我需要在.js文件中执行此操作)。但是,我怎样才能从打开的模态id到JavaScript?如何从开放引导模式获得'id'?
我已经尝试使用JavaScript代码,但它不起作用。有什么建议么?
_singlePost.html.erb
<a class="fg" href="#<%= p.id %>" data-toggle="modal">
<div id="withJosefin">
<%= p.title %>
</div>
</a>
<div id="<%= p.id %>" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<p><h3 id="myModalLabel"><%= p.title %></h3></p>
</div>
<div class="modal-body">
<%= raw(p.link) %>
</div>
</div>
pages.js.coffee
$ ->
if ('div.modal.hide.in').is(":visible")
currentId = $('.modal.fade.in').attr('id')
//Do something with currentId here
我看不出有任何的jQuery代码在这里 –
@roasted - 它与jQuery coffeecrap撒! – adeneo
@adeneo我不知道,thx的输入! –