我无法弄清楚为什么第二次单击按钮时jQuery不会触发。我很无能,如果你需要更多的代码或其他任何东西,请问。
HAML:
包含按钮的详细信息容器(%input.newRemark.newEntity.tm_button {:type =>" button",:value =>" New" } ):
.detail_header_container.remark
.red_title.detail_header.open#explore_management-configurationremarks_header="Remarks"
%input.newRemark.newEntity.tm_button{:type => "button", :value => "New"}
%div.listingContainer
.entityDetailsContainer
%table.configDetails{:class => "configuration-#{entity.id}"}
%thead
%tr
%th{:style => "width:25%"} Date
%th{:style => "width:65%"} Remark
%th{:style => "width:10%h"} Actions
%tbody
- ConfigurationRemark.where(:access_line_id => entity.access_line_id).sort(:created_at).each do |remark|
= render(:haml, :"explore_management/configurationremark_record", :locals => {:entity => remark})
jQuery赢得第二次的模式:
-# ModalContent
%div{:id => "add_remark_modal"}
%h1 Add remark to Access ID: #{entity.access_line_id}
%div.formErrors
%form.remarkForm#explore_management-configurationremarks_form{:action => "explore_management/configurationremarks", :method => "POST"}
%input{:type => "hidden", :name => "_method", :value => "POST"}
%input{:type => "hidden", :name => "access_line_id", :value => entity.access_line_id, :name => "entity[access_line_id]"}
%input{:type => "hidden", :name => "isFirst", :value => isFirst, :name => "config[isFirst]"}
%input{:type => "hidden", :name => "isLatest", :value => isLatest, :name => "config[isLatest]"}
%input{:type => "hidden", :name => "entity_index", :value => entity_index, :name => "config[entity_index]"}
%input{:type => "hidden", :name => "entity_array", :value => entity_array, :name => "config[entity_array]"}
%div
%label{:for => "remark"} Remark:
%input{:id => "remark", :type => "text", :name => "entity[remark]"}
%div#entityFormSubmit
%input.tm_button.add_remark{:type => "submit", :value => "Save"}
jQuery的:
// Click-event for dynamically added new-button(s)
$(document).on('click', '.newRemark', function(event){
// Open Remark popup
$("#add_remark_modal").modal();
// Set remark form save functions
onRemarkFormLoadSuccess();
});
function onRemarkFormLoadSuccess(data) {
var method = $(".remarkForm").find('input[name="_method"]').val();
var remarkFormOptions = { dataType: "html",
method: "POST",
success: onRemarkSaveSuccess,
error: onRemarkSaveError
};
$(".remarkForm").ajaxForm(remarkFormOptions);
}
function onRemarkSaveSuccess(record_html, statusText, jqXhr, jqForm) {
//remove form
$("#simplemodal-overlay").remove();
$("#simplemodal-container").remove();
var headerId = jqForm.attr('id').replace('_form', '_header');
var $listingContainer = $("#" + headerId).parent().find(".listingContainer");
var $tableBody = $("#" + headerId).parent().find("table.configDetails tbody");
//append new record
$tableBody.find("tr.nothingFound").remove();
var $newRecord = $(record_html).appendTo($tableBody);
//fade in$
$newRecord.hide();
$newRecord.css('background-color', '#FFFF66');
$newRecord.fadeIn(1000, function() { $newRecord.css('background-color', 'inherit');});
registerRecordActionHandlers($newRecord);
}
function onRemarkSaveError() {
alert("error");
}
function registerRecordActionHandlers($record) {
$record.click(onRecordClick);
$record.find(".recordActions a").click(onRecordActionClick);
}
VISUAL:
一些视觉效果可以更好地理解:
答案 0 :(得分:1)
我已将以下行添加到我的onClick()处理程序中。它会关闭剩余的打开模态。我第一次点击时没有模态打开,但我没有给出错误。
$.modal.close();
处理程序:
// Click-event for dynamically added new-button(s)
$(document).on('click', '.newRemark', function(event){
//Close
$.modal.close();
// Open Remark popup
$("#add_remark_modal").modal();
// Set remark form save functions
onRemarkFormLoadSuccess();
});