我在我的rails应用程序中使用bootstrap模式(Bootstrap版本3.2.0)
因为我已经为表单字段添加了自动对焦。首先打开模态它会自动聚焦字段。但是第二次它不起作用。
这里我添加了一些代码
<button type="button" id="myModalCreateButton" class="btn btn-primary" data-toggle="modal" data-target="#myModal" >
Create New Project
</button>
模态中的表格
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title second-color" id="myModalLabel">Create New Project</h4>
</div>
<%= form_for(@newproject) do |f| %>
<div class="modal-body">
<div class="form-group single-field">
<label for="exampleInputEmail1">Project Name</label>
<input type="text" class="form-control" id="newProjectField" placeholder="Enter project name" name="project[project_name]" autofocus >
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
<button type="button" class="btn btn-primary" id="createProjectButton" autofocus >
Create
</button>
</div>
<% end %>
</div>
</div>