最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery: .filter().css("visibility", "collapse") not working in IE, working in F

programmeradmin2浏览0评论

I have a table where in there are two dropdowns. On selecting a value from the first dropdown, the values of the second dropdown are displayed.

For this I have written the following function which gets invoked on the onchange event of the first dropdown:

function dataTypeChanged(selectedValue){

document.getElementById("nodeInputValidation").innerHTML = "";
var rows = $('table.intValidationTable tr');
rows.filter('.rangeTR').css("visibility", "collapse");
rows.filter('.listTR').css("visibility", "collapse");
rows.filter('.textListTR').css("visibility", "collapse");
rows.filter('.dateRangeTR').css("visibility", "collapse");
rows.filter('.dateListTR').css("visibility", "collapse");

var validationTypes = document.getElementById("validationType").options;
document.getElementById("validationType").value = "";
var datatype;
for(var i=0;i<validationTypes.length;i++)
{
    datatype = validationTypes[i].value.substring(0,validationTypes[i].value.indexOf("_"));

    if(datatype != selectedValue){
        $("#validationType option[value=" + validationTypes[i].value + "]").hide();
    }else{
        $("#validationType option[value=" + validationTypes[i].value + "]").show();
    }
}
}

This function works perfectly fine in Firefox. But somehow it doesn't work in IE 8.0.

EDIT: Earlier I thought this might be the cause of it. But its not.

var rows = $('table.intValidationTable tr');
rows.filter('.rangeTR').css("visibility", "collapse");
rows.filter('.listTR').css("visibility", "collapse");
rows.filter('.textListTR').css("visibility", "collapse");
rows.filter('.dateRangeTR').css("visibility", "collapse");
rows.filter('.dateListTR').css("visibility", "collapse");

Seems to be the other part of the function. Code that shows/hides options of the second dropdown is not working. All the options are getting displayed currently.

Can you guys help me with this.

Let me know if more code is required.

I have a table where in there are two dropdowns. On selecting a value from the first dropdown, the values of the second dropdown are displayed.

For this I have written the following function which gets invoked on the onchange event of the first dropdown:

function dataTypeChanged(selectedValue){

document.getElementById("nodeInputValidation").innerHTML = "";
var rows = $('table.intValidationTable tr');
rows.filter('.rangeTR').css("visibility", "collapse");
rows.filter('.listTR').css("visibility", "collapse");
rows.filter('.textListTR').css("visibility", "collapse");
rows.filter('.dateRangeTR').css("visibility", "collapse");
rows.filter('.dateListTR').css("visibility", "collapse");

var validationTypes = document.getElementById("validationType").options;
document.getElementById("validationType").value = "";
var datatype;
for(var i=0;i<validationTypes.length;i++)
{
    datatype = validationTypes[i].value.substring(0,validationTypes[i].value.indexOf("_"));

    if(datatype != selectedValue){
        $("#validationType option[value=" + validationTypes[i].value + "]").hide();
    }else{
        $("#validationType option[value=" + validationTypes[i].value + "]").show();
    }
}
}

This function works perfectly fine in Firefox. But somehow it doesn't work in IE 8.0.

EDIT: Earlier I thought this might be the cause of it. But its not.

var rows = $('table.intValidationTable tr');
rows.filter('.rangeTR').css("visibility", "collapse");
rows.filter('.listTR').css("visibility", "collapse");
rows.filter('.textListTR').css("visibility", "collapse");
rows.filter('.dateRangeTR').css("visibility", "collapse");
rows.filter('.dateListTR').css("visibility", "collapse");

Seems to be the other part of the function. Code that shows/hides options of the second dropdown is not working. All the options are getting displayed currently.

Can you guys help me with this.

Let me know if more code is required.

Share Improve this question edited Dec 11, 2012 at 9:12 DarkKnightFan asked Dec 10, 2012 at 12:58 DarkKnightFanDarkKnightFan 1,95314 gold badges42 silver badges61 bronze badges 6
  • Have you tried display: table-row-group? – user1326628 Commented Dec 10, 2012 at 13:00
  • no.. can you please elaborate it a little? – DarkKnightFan Commented Dec 10, 2012 at 13:01
  • No versions of Internet Explorer (including IE8) support the property values "inherit" or "collapse". – dsgriffin Commented Dec 10, 2012 at 13:01
  • Is there any alternative to "collapse" then for IE? I am using collapse since I dont want to show reserved space for the rows which are hidden. Looks ugly. – DarkKnightFan Commented Dec 10, 2012 at 13:03
  • Dup: IE8 - CSS visibility: collapse - Doesn't work? – SDC Commented Dec 10, 2012 at 13:12
 |  Show 1 more ment

3 Answers 3

Reset to default 4

No versions of Internet Explorer (including IE8) support the property values "inherit" or "collapse".

Use display:none; instead.

For example:

rows.filter('.rangeTR').css("display", "none");

visibility: collapse is not implemented in IE<8

Use display: none to hide the table elements.

see here : Alternative to visibility:collapse not working on IE and Chrome

and here : http://reference.sitepoint./css/visibility

Also check the code below :

if(datatype != selectedValue){
    $("#validationType option[value=" + validationTypes[i].value + "]").hide();
}else{
    $("#validationType option[value=" + validationTypes[i].value + "]").show();
}

maybe try adding quotes (wild guess, no real hope):

$("#validationType option[value='" + validationTypes[i].value + "']")

What version of jQuery are you using?

It would be cool to put together a jsFiddle for us.

Well it seems visibility: collapse can be used in IE as well. I am using it and it is working in both IE and Firefox. Dont know about other browsers apart from these two.

I have done the following:

HTML:

<table class="intValidationTable">

`<tr class="rangeTR" style="visibility: collapse;">`

`<tr class="listTR" style="visibility: collapse;">`

Javascript + Jquery:

var rows = $('table.intValidationTable tr');

var rangeTR = rows.filter('.rangeTR');

var listTR = rows.filter('.listTR');

rangeTR.css("visibility", "visible");

listTR.css("visibility", "collapse");

This should work!

Regarding my question, I guess the second part of the code is erroneous. Need to check that.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论