选择国家/地区时更改颜色

change color when a country selected

本文关键字:颜色 地区 国家 选择      更新时间:2023-09-26

当在<select>选项上选择国家/地区时,我正在尝试更改电话字段的颜色。

例如,如果有人选择英国,颜色必须变为红色。

但我不确定我做错了什么。这一点目前没有改变。

jQuery('select[name="address[_item1][country_id]"]').change(function() {
  if (jQuery(this).val() == 'GB') {
    jQuery('#_item1telephone').css("background-color", "yellow");
  })
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class=" required-entry countries required-entry select" name="address[_item1][country_id]" id="_item1country_id">
  <option value=""></option>
  <option value="GB">Uruguay</option>
</select>
<input type="text" class=" required-entry input-text required-entry" value="" name="address[_item1][telephone]" id="_item1telephone">

IF语句后面有一个无关的parens。此代码运行良好:

jQuery('select[name="address[_item1][country_id]"]').change(function() {
  if (jQuery(this).val() == 'GB') {
    jQuery('#_item1telephone').css("background-color", "yellow");
  } // <== here
});

jsFiddle演示