Jquery代码没有'在firefox/ie上运行不好
Jquery code doesn't work well on firefox/ie
我有以下代码(在jsfiddle上)
$(function(){
var $container = $('#gallery');
$container.isotope({
filter: '*',
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
var $optionSets = $('ul.nav'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function () {
var $this = $(this);
if ($this.hasClass('selected')) {
return false;
}
var $optionSet = $this.parents('ul.nav');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
});
// HASH HISTORY WITH JQUERY BBQ
$('ul.nav a').click(function () {
// get href attr, remove leading #
var href = $(this).attr('href').replace(/^#/, ''),
// convert href into object
// i.e. 'filter=.inner-transition' -> { filter: '.inner-transition' }
option = $.deparam(href, true);
// set hash, triggers hashchange on window
$.bbq.pushState(option);
return false;
});
//just a function to quickly add and remove .selected
function changeSelectedLink($elem) {
$elem.addClass('selected');
}
$(window).bind('hashchange', function (event) {
//checks if there is a hash in the url and puts hashes in hashOptions
$(".selected").removeClass("selected");
var hashOptions = window.location.hash ? $.deparam.fragment(window.location.hash, true) : {}, options = $.extend({}, hashOptions);
$('#gallery').isotope(options);
var hrefObj, hrefValue, $selectedLink;
//go over each hashOption and convert it to a variable
for (var key in options) {
hrefObj = {};
hrefObj[key] = options[key];
hrefValue = $.param(hrefObj);
$selectedLink = $('ul.nav').find('a[href="#' + hrefValue + '"]');
changeSelectedLink($selectedLink);
}
}).trigger('hashchange'); //this continues the hashchange event
});
此代码在chrome上运行良好。但在firefox 22和ie 10中,的行为很奇怪
当点击颜色时,一切都正常。返回时,代码的行为方式应该是清除.selected
并仅将其添加到正确的节点。结果是.selected
在DOM中被清除(如果我检查元素),但在屏幕上它没有。一旦我点击屏幕上的任何位置,该类就会被删除。
此外,如果我使用firebug等进行调试,则不会发生这种情况!
代码中有遗漏吗?
删除css中的a:focus
或在hashchange
中将blur
添加到$('.selected').removeClass('selected').blur();
http://jsfiddle.net/Q6SbU/7/
只有一个.selected
相关文章:
- Javascript赢得'不能在IE上编译,但可以在Chrome上运行
- 以下颜色更改功能在IE9和Firefox中运行良好,但在早期的IE或Chrome中则不然
- Javascript'元素'在ie中未定义,但在chrome和firefox中运行良好
- 通过运行条件编译防止JS泄露IE浏览器
- 是否可以从在Firefox或IE的网页中运行的Javascript启动Windows进程
- 没有在带有IE-FF的IFrame中运行的脚本是可以的
- jQuery fadeIn fadeOut"眨眼;在Chrome上,在FireFox和IE上运行良好
- SP2007使IE在运行jssor代码时挂起
- Jquery没有在firefox浏览器中调用Webservice方法,它在Chrome和IE中运行良好
- 长时间运行的脚本IE与Chrome/Firefox
- dart2js编译的Polymer Dart应用程序未在IE 11中运行
- 从Java脚本返回多个值,这些值不能在firefox上运行(在IE上运行良好)
- 内容编辑器 Web 部件脚本不在 IE 11 中运行(如果开发人员工具处于打开状态,则运行)
- JavaScript运行时错误:应为':'在IE中
- 在IE中没有开发人员控制台的情况下,JavaScript无法运行(can't属性为缺少控制台)
- 浏览器兼容性问题 - 无法在 IE 上运行
- 脚本在除IE之外的所有其他浏览器中都能完美运行
- Jquery对话框在IE中完美运行,但在FF和Chrome中则不然
- 强制仅限数字的js函数不'不适用于Firefox,但适用于Chrome;IE运行良好
- Will The Mark of The Web始终确保IE运行本地HTML文件