버튼을 두 번째로 클릭해도 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);
}
영상 :
더 나은 이해를위한 시각 자료 :
내 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();
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다