Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript RubyonRails,当用户不接受术语时,使用jQuery显示警报_Javascript_Jquery_Ruby On Rails_Ruby - Fatal编程技术网

Javascript RubyonRails,当用户不接受术语时,使用jQuery显示警报

Javascript RubyonRails,当用户不接受术语时,使用jQuery显示警报,javascript,jquery,ruby-on-rails,ruby,Javascript,Jquery,Ruby On Rails,Ruby,在我的Ruby on Rails应用程序中,我的表单如下所示: = simple_form_for @reservation do |f| = f.input :terms, as: :boolean = f.submit t('reservation.next'), class: "btn btn-default pull-right" 在我的模型中,我有虚拟属性术语: validates :terms, acceptance: true, on: :create, allow_n

在我的Ruby on Rails应用程序中,我的表单如下所示:

= simple_form_for @reservation do |f|
  = f.input :terms, as: :boolean 
  = f.submit t('reservation.next'), class: "btn btn-default pull-right"
在我的模型中,我有虚拟属性术语:

validates :terms, acceptance: true, on: :create, allow_nil: false
attr_accessor :terms
现在,当用户不接受术语应用程序时,将其重定向回flash错误。 但是现在我想当用户不接受规则时,提交按钮被禁用。有没有办法通过JQuery做到这一点? 提前感谢。

假设“接受规则”是复选框,然后使用jQuery编写一个逻辑,在单击复选框时启用和禁用提交按钮:

复选框使用唯一的
id
,并提交
按钮

<input type="checkbox" class="check" value="accept" id="accept"/>accept regulation

<input type="submit" value="click me" id="submitBtn" disabled/>


$(document).ready(function(){
    $('#accept').on("change",function(){
        var checkboxChecked = $(this).is(':checked');
        $('#submitBtn').prop('disabled',!checkboxChecked);
    });
});
接受监管
$(文档).ready(函数(){
$('#accept')。在(“更改”,函数()上){
var checkboxChecked=$(this).is(':checked');
$('#submitBtn').prop('disabled',!checkboxChecked);
});
});

假设“接受监管”是复选框,然后使用jQuery编写一个逻辑,在单击复选框时启用和禁用提交按钮:

复选框使用唯一的
id
,并提交
按钮

<input type="checkbox" class="check" value="accept" id="accept"/>accept regulation

<input type="submit" value="click me" id="submitBtn" disabled/>


$(document).ready(function(){
    $('#accept').on("change",function(){
        var checkboxChecked = $(this).is(':checked');
        $('#submitBtn').prop('disabled',!checkboxChecked);
    });
});
接受监管
$(文档).ready(函数(){
$('#accept')。在(“更改”,函数()上){
var checkboxChecked=$(this).is(':checked');
$('#submitBtn').prop('disabled',!checkboxChecked);
});
});

假设“接受监管”是复选框,然后使用jQuery编写一个逻辑,在单击复选框时启用和禁用提交按钮:

复选框使用唯一的
id
,并提交
按钮

<input type="checkbox" class="check" value="accept" id="accept"/>accept regulation

<input type="submit" value="click me" id="submitBtn" disabled/>


$(document).ready(function(){
    $('#accept').on("change",function(){
        var checkboxChecked = $(this).is(':checked');
        $('#submitBtn').prop('disabled',!checkboxChecked);
    });
});
接受监管
$(文档).ready(函数(){
$('#accept')。在(“更改”,函数()上){
var checkboxChecked=$(this).is(':checked');
$('#submitBtn').prop('disabled',!checkboxChecked);
});
});

假设“接受监管”是复选框,然后使用jQuery编写一个逻辑,在单击复选框时启用和禁用提交按钮:

复选框使用唯一的
id
,并提交
按钮

<input type="checkbox" class="check" value="accept" id="accept"/>accept regulation

<input type="submit" value="click me" id="submitBtn" disabled/>


$(document).ready(function(){
    $('#accept').on("change",function(){
        var checkboxChecked = $(this).is(':checked');
        $('#submitBtn').prop('disabled',!checkboxChecked);
    });
});
接受监管
$(文档).ready(函数(){
$('#accept')。在(“更改”,函数()上){
var checkboxChecked=$(this).is(':checked');
$('#submitBtn').prop('disabled',!checkboxChecked);
});
});

像这样的东西应该可以完成这项工作。您需要将本例中的jQuery选择器(
#您的#预订#条款(terms)复选框
#您的#提交(submit)按钮
)更改为正确,以匹配这些元素的实际id

= simple_form_for @reservation do |f|
  = f.input :terms, as: :boolean
  = f.submit t('reservation.next'), class: "btn btn-default pull-right"

:javascript
  $(document).ready(function(){
    $('input#your_reservation_terms_checkbox').on('change', function(){
      checked = $(this).is(':checked');
      $('#your_submit_button').prop('disabled', !checked);
      $('.warning-message').remove()
      if(!checked){
        $('#your_submit_button').before('<span class="warning-message">You must accept the terms</span>');
      }
    });
  });
=simple_form_表示@reservation do|f|
=f.输入:术语,如::布尔值
=f.submit t('reservation.next'),类:“btn btn默认向右拉”
:javascript
$(文档).ready(函数(){
$('input#your _reservation _terms _checkbox')。on('change',function(){
checked=$(this).is(':checked');
$(“#您的提交按钮”).prop('disabled',!checked);
$('.warning message').remove()
如果(!选中){
$('您的'提交'按钮')。在('您必须接受条款')之前;
}
});
});

像这样的东西应该可以完成这项工作。您需要将本例中的jQuery选择器(
#您的#预订#条款(terms)复选框
#您的#提交(submit)按钮
)更改为正确,以匹配这些元素的实际id

= simple_form_for @reservation do |f|
  = f.input :terms, as: :boolean
  = f.submit t('reservation.next'), class: "btn btn-default pull-right"

:javascript
  $(document).ready(function(){
    $('input#your_reservation_terms_checkbox').on('change', function(){
      checked = $(this).is(':checked');
      $('#your_submit_button').prop('disabled', !checked);
      $('.warning-message').remove()
      if(!checked){
        $('#your_submit_button').before('<span class="warning-message">You must accept the terms</span>');
      }
    });
  });
=simple_form_表示@reservation do|f|
=f.输入:术语,如::布尔值
=f.submit t('reservation.next'),类:“btn btn默认向右拉”
:javascript
$(文档).ready(函数(){
$('input#your _reservation _terms _checkbox')。on('change',function(){
checked=$(this).is(':checked');
$(“#您的提交按钮”).prop('disabled',!checked);
$('.warning message').remove()
如果(!选中){
$('您的'提交'按钮')。在('您必须接受条款')之前;
}
});
});

像这样的东西应该可以完成这项工作。您需要将本例中的jQuery选择器(
#您的#预订#条款(terms)复选框
#您的#提交(submit)按钮
)更改为正确,以匹配这些元素的实际id

= simple_form_for @reservation do |f|
  = f.input :terms, as: :boolean
  = f.submit t('reservation.next'), class: "btn btn-default pull-right"

:javascript
  $(document).ready(function(){
    $('input#your_reservation_terms_checkbox').on('change', function(){
      checked = $(this).is(':checked');
      $('#your_submit_button').prop('disabled', !checked);
      $('.warning-message').remove()
      if(!checked){
        $('#your_submit_button').before('<span class="warning-message">You must accept the terms</span>');
      }
    });
  });
=simple_form_表示@reservation do|f|
=f.输入:术语,如::布尔值
=f.submit t('reservation.next'),类:“btn btn默认向右拉”
:javascript
$(文档).ready(函数(){
$('input#your _reservation _terms _checkbox')。on('change',function(){
checked=$(this).is(':checked');
$(“#您的提交按钮”).prop('disabled',!checked);
$('.warning message').remove()
如果(!选中){
$('您的'提交'按钮')。在('您必须接受条款')之前;
}
});
});

像这样的东西应该可以完成这项工作。您需要将本例中的jQuery选择器(
#您的#预订#条款(terms)复选框
#您的#提交(submit)按钮
)更改为正确,以匹配这些元素的实际id

= simple_form_for @reservation do |f|
  = f.input :terms, as: :boolean
  = f.submit t('reservation.next'), class: "btn btn-default pull-right"

:javascript
  $(document).ready(function(){
    $('input#your_reservation_terms_checkbox').on('change', function(){
      checked = $(this).is(':checked');
      $('#your_submit_button').prop('disabled', !checked);
      $('.warning-message').remove()
      if(!checked){
        $('#your_submit_button').before('<span class="warning-message">You must accept the terms</span>');
      }
    });
  });
=simple_form_表示@reservation do|f|
=f.输入:术语,如::布尔值
=f.submit t('reservation.next'),类:“btn btn默认向右拉”
:javascript
$(文档).ready(函数(){
$('input#your _reservation _terms _checkbox')。on('change',function(){
checked=$(this).is(':checked');
$(“#您的提交按钮”).prop('disabled',!checked);
$('.warning message').remove()
如果(!选中){
$('您的'提交'按钮')。在('您必须接受条款')之前;
}
});
});

下面是一个示例,介绍如何执行此操作

<input type="checkbox" id="checkbox_id" />
<input type="button" id="button_id" value="Submit" />

$('#checkbox_id').click(function() {
        if ($(this).is(':checked')) {
            $('#button_id').attr('disabled', 'disabled');
        } else {
            $('#button_id').removeAttr('disabled');
        }
    });

$('#复选框_id')。单击(函数(){
如果($(this).is(':checked')){
$('#按钮id').attr('disabled','disabled');
}否则{
$(“#按钮_id”).removeAttr('disabled');
}
});

下面是一个示例,介绍如何执行此操作

<input type="checkbox" id="checkbox_id" />
<input type="button" id="button_id" value="Submit" />

$('#checkbox_id').click(function() {
        if ($(this).is(':checked')) {
            $('#button_id').attr('disabled', 'disabled');
        } else {
            $('#button_id').removeAttr('disabled');
        }
    });

$('#复选框_id')。单击(函数(){
如果($(this).is(':checked')){
$('#按钮id').attr('disabled','disabled');
}否则