d3”;隐藏的“;属性bug或我代码中的bug

d3 "hidden" attribute bug or bug in my code?

本文关键字:bug 代码 隐藏 d3 属性      更新时间:2023-09-26

我建立了一个网页,在1956年和1999年拍摄的两张蟹状星云照片之间切换。该页面在Chrome和Firefox中的工作方式与我预期的一样,但在IE10中则不然。我不确定问题是在IE10中,而不是我的代码,因为我不得不破解我的代码才能在Chrome和Firefox中工作。

以下是IE10中失败的javascript片段,在Chrome和Firefox中也能正常工作:

if(curHelp=="Show Text"){
    curHelp = "Hide Text";
    d3s=d3.selectAll("p");
    d3s.attr("hidden",false);
    d3s[0][0].hidden=false; // d3s.attr("hidden",false) doesn't work.
    d3s[0][1].hidden=false; // It sets  all "hidden" attribute for paragraphs to true.
    d3s[0][2].hidden=false; // I hacked in these 4 lines just to get the page to work.
    d3s[0][3].hidden=false; 
}else{
    curHelp = "Show Text";
    d3s=d3.selectAll("p");
    d3s.attr("hidden",true);  // this works but maybe because it's a bug?
}

行"d3s.attr("hidden",false)将所有段落的隐藏属性设置为true。

我认为这个错误在我的代码中,但我不确定我做错了什么,因为.attr函数调用在我打算隐藏段落时按预期工作,但在我打算显示段落时失败。

这是我正在处理的页面的链接。

试试这个:

d3.selectAll("p").style("display", "none") 

可见性是CSS属性。应该使用style来设置它,而不是.attr