JQuery更改CSS显示不起作用

Dou*_*eux 1 jquery internet-explorer google-chrome

我有这个工作在chrome和firefox上,基本上当用户点击一个子图像时,它通过改变它的显示属性从hide到show来改变主图像.这是我的img元素.

<img id="lg1" src="http...
<img id="lg2" style="display:none" src="http...
<img id="lg3" style="display:none" src="http...
Run Code Online (Sandbox Code Playgroud)

我的js看起来像这样:

    $('#graph1').click(function() {
    $("#lg1").css("display","inherit");
    $("#lg2").css("display","none");
    $("#lg3").css("display","none");
});

$('#graph2').click(function() {
    $("#lg1").css("display","none");
    $("#lg2").css("display","inherit");
    $("#lg3").css("display","none");
});

$('#graph3').click(function() {
    $("#lg1").css("display","none");
    $("#lg2").css("display","none");
    $("#lg3").css("display","inherit");
});
Run Code Online (Sandbox Code Playgroud)

在IE中,我收到此错误:

Could not get the display property. Invalid argument.
Run Code Online (Sandbox Code Playgroud)

无论如何我可以改变我的代码,使其与Chrome,FF和IE一起使用?

谢谢!

T.J*_*der 6

遗憾的是,"inherit"不是IE上的有效显示值.你可以尝试"",它应该工作(实例)禁止一些样式表规则另外说明该元素(像这样).

偏离主题,但如果你想要一个较短的写作方式,.css("display", "none")你可以使用.hide().:-)