非常简单的例子: http://jsbin.com/ohude
单击按钮 1,“hello2”文本 p 应将 z-index 更改为 89。单击按钮 2,z-index 应再次更改。这在 Firebug 中很明显。但它在 IE8 中不起作用。
有人可以确认吗?
谢谢。
最佳答案
我没有 IE8,也不知道 jQuery 代码。
您是要更改查看的文本还是仅更改 z-index?如果 z-index 和查看的文本,在 Safari 中是不行的。
为了我的测试,我将您原来的 jQuery 样式函数更改为:
- 提醒您的原始更改(注意 style.zIndex,而不是 z-index);和
- 然后更改文本 nodeValue 以反射(reflect) z-index 的变化。
首先,我将您的 css 更改为 css('zIndex','89') 以查看是否改变了结果。 无论是 css('zIndex'...) 还是 css('z-index'...),对我都有效。
正如我所说,我不懂 jQuery。但是在 IE8 中测试以下代码片段后,如果它不起作用,请尝试将 css arg 更改为 'zIndex',只是为了笑。
测试:
$('#click').click(function () {
$('#hello').css('z-index','89');
var pid = document.getElementById('hello');
alert('pid.style.zIndex: ' + pid.style.zIndex);
pid.firstChild.nodeValue = "Hello2 " + pid.style.zIndex;
});
$('#click2').click(function () {
$('#hello').css('z-index','10');
var pid = document.getElementById('hello');
alert('pid.style.zIndex: ' + pid.style.zIndex);
pid.firstChild.nodeValue = "Hello2 " + pid.style.zIndex;
});
});
抱歉弄乱了您的 JQuery 代码。 :D
关于javascript - 你能在IE8中用JS改变z-index吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/890191/