Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 触发change函数并在jquery中设置select的值?_Javascript_Jquery_Ruby On Rails - Fatal编程技术网

Javascript 触发change函数并在jquery中设置select的值?

Javascript 触发change函数并在jquery中设置select的值?,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,嗨,我已经给出了代码 $('#filled-in-box2').on('click', function () { if ($('#filled-in-box2').is(':checked')) { $('select#employee_permanent_address_attributes_country').val($('select#employee_contact_attributes_country').val()).change(); $('s

嗨,我已经给出了代码

$('#filled-in-box2').on('click', function () {
    if ($('#filled-in-box2').is(':checked')) {
        $('select#employee_permanent_address_attributes_country').val($('select#employee_contact_attributes_country').val()).change();
      $('select#permanent_address_state_code').val($('select#contact_state_code').val());
    }
});
因此,我希望在更改后功能或更改功能触发时,只有永久地址\u状态\u代码值将设置为与联系人\u状态\u代码值相同。 我也尝试过这个代码,但它不起作用

$('#filled-in-box2').on('click', function () {
    if ($('#filled-in-box2').is(':checked')) {
        $('select#employee_permanent_address_attributes_country').val($('select#employee_contact_attributes_country').val()).trigger('change',function(){
            $('select#permanent_address_state_code').val($('select#contact_state_code').val());
        });

    }
  });
当单击复选框“快照未填充状态”时,我正在附加快照

请指导我如何解决这个问题。提前谢谢

$('#filled-in-box2').on('click', function () {
   if ($('#filled-in-box2').is(':checked')) {                           $('select#employee_permanent_address_attributes_country').val($('select#employee_contact_attributes_country').val());
    $('select#permanent_address_state_code').val($('select#contact_state_code').val()); 
 }
 });

当您单击复选框时,仅此一项就可以满足您更改永久州和国家的要求。

这些是选择而不是复选框。这就是代码不起作用的原因之一。