简体   繁体   English

触发变更功能并在jquery中设置select的值?

[英]Trigger change function and set the value of select in jquery?

Hi I am having given code 嗨,我已经给出了代码

$('#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());
    }
});

So I want after change function or when change function trigger at that time only permanent_address_state_code value will set same as contact_state_code value . 所以我想要更改函数之后或当更改函数在那时触发时,只有permanent_address_state_code值将设置为contact_state_code值 I have tried this code too but its not working 我也尝试过此代码,但无法正常工作

$('#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());
        });

    }
  });

I am attachiing snapshot when click on check box it does not populate state 我在单击不填充状态的复选框时附加快照 在此处输入图片说明

Please guide me how to solve this. 请指导我如何解决此问题。 Thanks in advance. 提前致谢。

$('#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()); 
 }
 });

This alone will work for your requirement to change permanent state and country when you click on checkbox. 当您单击复选框时,仅此一项就可以满足您更改永久性州和国家/地区的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM