jQuery not working in IE when selecting an item in dropdown
I have a dropdown that shows countries. When the user selects United States or Canada, then another drop drop will appear. Everything works with Firefox, but not with Internet Explorer.
$(document).ready(function() {
$('.CountriesDropDown').change(changeAddressOptions);
// alert('loaded');
// call change event in case value was cached from reset
});
function changeAddressOptions(){
// this is drop down
var jsThis = $(this);
var selectedVal = jsThis.val();
var targetElementWrapper = jsThis.parents('li:first').siblings('.addressContentsWrapper');
var elementToPopulate = targetElementWrapper.children('.addressContents');
if (selectedVal == null || selectedVal == '') {
targetElementWrapper.fadeOut();
elementToPopulate.empty();
}
else 开发者_如何学Python{
var loadingImage = jsThis.siblings('.loadingImage');
loadingImage.show();
var bindingPrefix = extractBindingPrefix(jsThis);
if (selectedVal == 'US') {
var elementUrl = '/AddressInfo.aspx/UsAddressInfo/?bindingPrefix=' + bindingPrefix;
}
else if (selectedVal == 'CA') {
var elementUrl = '/AddressInfo.aspx/CanadaAddressInfo/?bindingPrefix=' + bindingPrefix;
}
else {
var elementUrl = '/AddressInfo.aspx/InternationalAddressInfo/?bindingPrefix=' + bindingPrefix;
}
targetElementWrapper.hide();
elementToPopulate.empty();
$(elementToPopulate).load(elementUrl, countryLoadComplete);
}
}
function countryLoadComplete() {
var wrapper = $(this).parents('.addressContentsWrapper:first');
$(wrapper).fadeIn('fast', hideLoadingImage);
}
function hideLoadingImage() {
var loadingImage = $(this).siblings().find('.loadingImage');
loadingImage.hide();
}
function extractBindingPrefix(element) {
// hack - grab binding prefix from neighboring labe, since lastIndexOf never works;
var bindingPrefixHolder;
var bindingPrefix;
bindingPrefixHolder = $(element).siblings('.bindingPrefix');
/// var lastPeriod = elementName.indexOf('.', 0);
// if (lastPeriod = -1)
// bindingPrefix = '';
//else {
// bindingPrefix = elementName.substring(0, lastPeriod);
// }
bindingPrefix = bindingPrefixHolder.html();
return bindingPrefix;
}
You have to wrap you jQuery objects in $() everytime you use a jQuery function:
var jsThis = $(this);
var selectedVal = jsThis.val();
Should be
var jsThis = $(this);
var selectedVal = $(jsThis).val();
This needs to be fixed in numerous places in your script.
精彩评论