Я только что проверил, что мой код javascript отлично работает во всех браузерах, кроме IE. Как возможно, что скрипт правильно читается и выполняется в Chrome, Safari ... но IE обнаруживает необъяснимую ошибку и отказывается запускать код?Код Javascript не работает только в IE
$(document).ready(function() {
var NewsNavigator = {
init: function(config) {
this.news = config.news;
this.newsNum = this.news.length;
this.navbuttons = config.navbuttons;
this.prevButton = config.prevButton;
this.nextButton = config.nextButton;
this.displayatonce = config.displayatonce;
this.maxSteps = Math.ceil(this.newsNum/this.displayatonce);
this.counter = 0;
this.navigateNews();
this.enableNav();
this.checkButtonsVisibility();
},
showNews: function() {
var start = this.counter * this.displayatonce;
var end = this.counter * this.displayatonce + (this.displayatonce - 1);
for (i=start; i<=end; i++) {
this.news.eq(i).show();
}
},
hideAllNews: function() {
console.log("hiding news");
this.news.hide();
},
navigateNews: function() {
this.hideAllNews();
this.showNews();
},
checkButtonsVisibility: function() {
if (this.counter <= 0)
{
this.prevButton.css('visibility', 'hidden');
}
else
{
this.prevButton.css('visibility', 'visible');
}
if (this.counter >= this.maxSteps - 1)
{
this.nextButton.css('visibility', 'hidden');
}
else
{
this.nextButton.css('visibility', 'visible');
}
},
enableNav: function() {
self = this;
this.navbuttons.on('click', function(event) {
if (($(this).data('dir') === 'prev') && (self.counter > 0)) {
self.counter--;
self.navigateNews();
} else if (($(this).data('dir') === 'next') && (self.counter < self.maxSteps - 1)) {
self.counter++;
self.navigateNews();
}
self.checkButtonsVisibility();
event.preventDefault();
});
}
};
NewsNavigator.init({
news: $('div#cat-news').find('div.oneCol'),
displayatonce: 3,
navbuttons: $('div#nav').find('a'),
prevButton: $('div#nav a.prec'),
nextButton: $('div#nav a.succ')
});
});
Сообщение об ошибке в IE9
SCRIPT438: The object doesn't support the 'checkButtonsVisibility' property or method.
NewsNavigator.js, Row 69 Character 5
Мы не можем помочь, не видя ваш javascript. – Aidanc
@ haunted85 Все браузеры имеют свои тонкие отличия в том, как JavaScript взаимодействует с документами, а также о том, какая версия ECMAScript (и какая версия) реализована. Вам нужно будет показать нам свой код для дальнейшей помощи. – Sampson
Также убедитесь, что у вас нет объектных литералов с запятыми прямо перед закрытием '}' – Pointy