简体   繁体   English

jQuery不适用于IE 6和7上的表的CSS规则

[英]JQuery doesn't apply css rule to table on IE 6 and 7

I have a form with 2 radio buttons and when a user clicks on one of the radio buttons a select input appears. 我有一个带有2个单选按钮的表单,当用户单击其中一个单选按钮时,将显示一个选择输入。
It works on Chrome, FF and IE 8+ but it doesn't work with IE 6 and 7. 它适用于Chrome,FF和IE 8+,但不适用于IE 6和7。

Here is what I've done : 这是我所做的:

HTML HTML

<input type="radio" name="Equipier" value="oui" id="oui">Oui
<input type="radio" name="Equipier" value="non" id="non">Non

<select name="choixequipier" id="selectequipier">
    <option value="non">-</option>
    <option value="matin">Matin</option>
    <option value="apres midi">Arpès-midi</option>
    <option value="nuit">Nuit</option>
    <option value="week end">Week-end</option>
</select>

JS JS

$(document).ready(function () {
    $("input[name=Equipier]:radio").change(function () {
        if ($("#oui").attr("checked")) {
            $('#equipierchoix').css("display", "table-row");
        }
        else {
            $('#equipierchoix').css("display", "none");
            $('#selectequipier option[value="non"]').attr("selected", "selected");
        }
    })
});

I'm using jQuery 1.7.1 我正在使用jQuery 1.7.1

How can I solve the problem for IE 6 and 7 ? 我该如何解决IE 6和7的问题?

EDIT 编辑

I'm able to enter in the if statement so it's a problem with this line : 我可以输入if语句,所以这行有问题:

$('#equipierchoix').css("display", "table-row");

Well, Internet Explorer has this thing called conditional tags in older versions 好吧,Internet Explorer在旧版本中有一个叫做条件标签的东西

This is all IE code of IE 8 and above 这是IE 8及更高版本的所有IE代码

<!--[if (gt IE 8)|!(IE)]><!-->
<script type="text/javascript">
$(document).ready(function () {
    $("input[name=Equipier]:radio").change(function () {
        if ($("#oui").attr("checked")) {
            $('#equipierchoix').css("display", "table-row");
        }
        else {
            $('#equipierchoix').css("display", "none");
            $('#selectequipier option[value="non"]').attr("selected", "selected");
        }
    })
});
</script>
<!--<![endif]-->

Here you put any work arounds for anything obsolete and lesser than IE 8(lt = lesser than) 在这里,您要为所有过时且小于IE 8(lt =小于)的东西进行解决。

<!--[if lt IE 8]>
<script type="text/javascript">
$(document).ready(function () {
    $("input[name=Equipier]:radio").change(function () {
        if ($("#oui").attr("checked")) {
            $('#equipierchoix').css("display", "block");
        }
        else {
            $('#equipierchoix').css("display", "none");
            $('#selectequipier option[value="non"]').attr("selected", "selected");
        }
    })
});
</script>
<![endif]-->

I think that display:block should work, but I don't have a proper version of IE at hand to test. 我认为display:block应该可以工作,但是我手头没有合适版本的IE进行测试。

And otherwise you can play with $('#equipierchoix').css("visibility", "hidden"); 否则,您可以使用$('#equipierchoix').css("visibility", "hidden"); and $('#equipierchoix').css("visibility", "visible"); $('#equipierchoix').css("visibility", "visible"); if the display:block fails for IE 6 & 7 code 如果display:block对于IE 6和7代码失败

EDIT FOR CLARIFICATION 编辑澄清

You need to put both blocks on the page. 您需要将两个块都放在页面上。
In the first block you place all the code that should only run for "recent" browsers 在第一块中,放置仅应在“最新”浏览器上运行的所有代码

in the second block you place all the code that is going to have to work or adapted for functionality for ie6-7 在第二个块中,放置将要工作或适用于ie6-7功能的所有代码

code that works for anything doesn't have to be encased by the conditional comments. 适用于任何事物的代码不必被条件注释所包围。

Internet Explorer supports display: table-row only since version 8.0. Internet Explorer支持display: table-row仅从8.0版开始的display: table-row

Solve the problem by dropping support for dead browsers, or by using an actual table. 通过删除对无效浏览器的支持或使用实际表来解决该问题。

To obtain "checked", you should use 'prop' not 'attr': 要获取“选中”,您应该使用“ prop”而不是“ attr”:

$("#oui").prop("checked")

Also '#equipierchoix' doesn't seem to be the right ID, it would appear to be: 同样,“#equipierchoix”似乎不是正确的ID,而是:

$('#selectequipier').css("display", "none");

Check caniuse.com to check what else is valid for those very old browsers, although I see that that site is starting to phase them out. 请访问caniuse.com,以检查对那些非常旧的浏览器还有哪些有效的方法,尽管我发现该网站已开始逐步淘汰它们。

A sample plunk is here: 这里有一个小样:

Plunkr Plunkr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM