레일 애플리케이션을 개발 중입니다. index.html.haml에서 _form.html.haml (새 작업 및 편집 작업의 경우)도 렌더링 중입니다. 클릭하면 색인 페이지에 "그룹 추가"링크가있어서 양식의 특정 필드를 비활성화해야합니다. 나는 그것에 대한 jquery 코드를 작성했다. 내 문제는 내가 링크를 클릭하면 필드가 비활성화되어 (회색으로 표시됨) 즉시 즉시 다시 활성화됩니다. 페이지를 새로 고침하면 비활성화 된 필드가 표시됩니다. 링크를 클릭 한 다음 사용 중지 된 상태가 유지되기를 원합니다. 새로운 편집 작업에 대한jquery가 작동하지 않음
jQuery를 코드
$(function(){
$("#add_requirement_group").click(function() {
$("#requirement_text_full, #requirement_requirement_type").prop("disabled", true);
});
});
양식.
= form_for ([@requirement.requirements_template, @requirement]), html: { class: "form-horizontal" } do |f|
- if @requirement.errors.any?
#error_explanation
%h2= "#{pluralize(@requirement.errors.count, "error")} prohibited this requirement from being saved:"
%ul
- @requirement.errors.full_messages.each do |msg|
%li= msg %fieldset
.control-group
= f.hidden_field :parent_id
.control-group
= f.label :text_brief, class: "control-label"
.controls
= f.text_field(:text_brief, class: "input-block-level")
.control-group
= f.label :text_full, class: "control-label"
.controls
= f.text_area(:text_full, rows: 5, class: "input-block-level")
.control-group
= f.label :obligation, class: "control-label"
.control-group
= f.label :requirement_type, class: "control-label"
.controls
= f.select :requirement_type, options_for_select([:text, :numeric, :date, :enum]), include_blank: true
.actions.pull-right
%br/
= f.submit 'Save', class: 'btn btn-info'
= button_to 'Finish', '#', class: 'btn btn-info', method: :get
index.html.haml
%hr
.row-fluid
.span4
%fieldset.template_outline
%strong Template Outline
%br
= link_to 'Add Group', new_requirements_template_requirement_path(@requirements_template), id: "add_requirement_group"
%hr
= render 'form'
나는 그것이 같은 간단한 코드 조각 그러나 예상대로 어떤 이유로 비활성화가 작동하지 알고있다.
안녕하십니까. 정말 고마워요.하지만 빠른 질문입니다.이 경우 DOM 요소의 기본 동작을 억제하기 위해 무엇을 말할까요? – bhvd
의미가 무엇인지 알지 못했습니다. 다시 감사하겠습니다. – bhvd
문제 없습니다. 광산을 답변으로 표시 할 수 있다면 감사하겠습니다. 감사합니다. :) –