代码与 IE 不兼容?
$(document).ready(function() {
var url = document.location.toString();
$('.tab').click(function() {
if($(this).is(".active")) {
return;
}
var classy = $(this).attr("class").split(" ").splice(-1);
var innerhtml = $('.content.'+classy).text();
$('#holder').html(innerhtml);
$('.tab').removeClass('active');
$(this).addClass('active');
});
var url = document.location.toString();
if(url.match(/#([a-z])/)) {
//There is a hash, followed by letters in it, therefore the user is targetting a page.
var split = url.split("#").splice(-1);
$('.tab.'+split).click();
}
else {
$('.tab:first').click();
}
});
嘿,我的一位评论者刚刚告诉我,这段代码在 IE 中不起作用。我一生都无法弄清楚为什么。每当您切换选项卡时,选项卡的内容都不会更改。同时#holder div 的内容是所有选项卡的组合。
有什么想法吗?
$(document).ready(function() {
var url = document.location.toString();
$('.tab').click(function() {
if($(this).is(".active")) {
return;
}
var classy = $(this).attr("class").split(" ").splice(-1);
var innerhtml = $('.content.'+classy).text();
$('#holder').html(innerhtml);
$('.tab').removeClass('active');
$(this).addClass('active');
});
var url = document.location.toString();
if(url.match(/#([a-z])/)) {
//There is a hash, followed by letters in it, therefore the user is targetting a page.
var split = url.split("#").splice(-1);
$('.tab.'+split).click();
}
else {
$('.tab:first').click();
}
});
Hey, I was just informed by one of my commenters that this code doesn't work in IE. I can't for the life of me figure out why. Whenever you switch tabs, the content of the tab doesn't change. Meanwhile the content of the #holder div is all the tabs combined.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是您想要的答案,但我会 严重建议如果可以的话,研究jQueryui选项卡小部件。至少,它让我的生活更容易处理这些事情。
Not the answer you're after, but I'd seriously recommend looking into the jQueryui tabs widget if you can. It's made my life a lot easier dealing with this stuff at least.
如果没有 IE 版本和页面来查看到底发生了什么,很难说清楚 - 但这里有一些最好的猜测:
更改:
到:
更改:
到:
更改:
到:
Hard to tell without an IE version and a page to look at what exactly is happening- but here are some best guesses:
change:
to:
change:
to:
change:
to:
我做了 Ryan 建议的所有更改,除了根据需要在“.content”和句点之间添加空格之外。如果没有源代码,他就不可能知道。
我将您的 .splice(-1) 更改为 [1],以便我选择数组中的第二项,即类名。看起来 .splice(-1) 在 IE 和其他浏览器中的行为有所不同。
我已经用 IE 7-8 测试了代码,它可以工作。
现在的源代码:
I did all changes which Ryan suggested except adding the space between '.content' and the period as it is needed. He could not have known without the source code.
I changed your .splice(-1) to [1] so that I'm choosing the second item in the array, which is the class name. It looks like .splice(-1) is behaving differently in IE and other browsers.
I have tested the code with IE 7-8 and it works.
Source code as it is now: