选择国家时改变颜色

change color when a country selected

我正在尝试在 <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 语句后有一个无关的括号。此代码工作正常:

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

jsFiddle Demo