我用Ajax发送了我的引导模式这个内容:
<div class="list-of-players text-center">
<div class="list">
@foreach($team->players as $player)
<a class="player_choose" id="player_id_Standard_{{$player->id}}">
<div class="player">
<span class="p_name"><span class="flag-icon {{$player->nationality->flag}}"></span> {{$player->fullname}}</span>
</div>
</a>
@endforeach
</div>
</div>
但是当我想通过这段代码选择这个模态窗口的某个元素时:
$('.player_choose').click(function () {
$('.modal').modal('hide');
});
它不起作用。有什么问题?也许js不会看到&#34; player_choose&#34; ajax之后的元素?
答案 0 :(得分:2)
是。在使用ajax获取此元素之前,您的脚本将执行。您应该使用event delegation。这应该有效:
Completed 500 Internal Server Error in 69ms (ActiveRecord: 1.0ms)
ActionView::Template::Error (uninitialized constant Cube::Cubecard):
22:
23: <p>
24: Add a Card:
25: <%= form_with(model: [ @cube, @cube.cubecards.build ], local: true) do |form| %>
26: <p>
27: <%= number_field(:card, :id, in: 1.0..8000.0, step: 1) %>
28: </p>
app/views/cubes/show.html.erb:25:in `_app_views_cubes_show_html_erb___540381856_44810532'