选择国家/地区时更改颜色(change color when a country selected)
我想在<select>选项上<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">I am trying to change color of a telephone field when a country is selected on the <select> options.
For example if someone selects UK the color must change to Red.
But I'm not sure what I'm doing wrong. This doesn't change at the moment.
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演示
You had an extraneous parens after the IF statement. This code works fine:
jQuery('select[name="address[_item1][country_id]"]').change(function() { if (jQuery(this).val() == 'GB') { jQuery('#_item1telephone').css("background-color", "yellow"); } // <== here });jsFiddle Demo
更多推荐
发布评论