[英]Javascript while loop not rendering html in IE8
EDIT: ( SEE ANSWER BELOW ) 编辑:(请参阅下面的答案)
I've been a long time viewer of stackoverflow but my first question today since I didn't found any answer anywhere... I have a strange behavior with my javascript code. 我一直是stackoverflow的长期查看者,但是今天我的第一个问题是,因为我在任何地方都找不到任何答案...我的javascript代码有奇怪的行为。 I've tried a lot of different way but never been able to correct the problem.
我尝试了许多不同的方法,但从未能够解决问题。 What I want is to collapse and expand some element when I click on a button... Normally it would be simple and it's working In Chrome but not in IE8.
我想要的是当我单击按钮时折叠并展开某些元素...通常,这很简单,并且可以在Chrome中工作,但不能在IE8中工作。
here is my javascript code: 这是我的JavaScript代码:
function collapseClick(obj) { var group = $(obj).attr('data-maingroup'); console.log("collapseClick on group:" + group); console.log("obj class before:" + $(obj).attr('class')); if ($(obj).hasClass("toggleExpand")) { $(obj).addClass("toggleMinus"); $(obj).removeClass("toggleExpand"); } else { $(obj).removeClass("toggleMinus"); $(obj).addClass("toggleExpand"); } console.log("obj class after:" + $(obj).attr('class')); $('div[data-group="' + group + '"]').each(function (index, item) { console.log("div loop for group:" + group + " index:" + index); $(this).toggle(); });
} }
here is my Html that is rendered: 这是呈现的我的HTML:
<div id="chart">
<div class="leftPart">
<div class="header">name</div>
<div class="item parent">
<a id="collapse_Integrated_Planning" onclick="collapseClick(this);return false;" style="float:left;" class="leftcollapse toggleMinus" data-maingroup="Integrated Planning"></a>Integrated Planning
</div>
<div class="item child gantShow" data-group="Integrated Planning">John Smith</div>
<div class="item child gantShow" data-group="Integrated Planning">Alex Smith</div>
</div>
<div class="gantMainControl" id="gantControl">
<div class="header">
<div class="headerRow">
<div class="headerRowYear" id="headerYear">
<div class="headerCellYear" style="width:1499.5983985355874px">2013</div>
</div>
</div>
<div class="headerRow">
<div class="headerCellMonth" style="width:126.42890508110469px">January</div>
<div class="headerCellMonth" style="width:114.1938497506752px">February</div>
<div class="headerCellMonth" style="width:126.42890508110469px">March</div>
<div class="headerCellMonth" style="width:122.35055330429486px">April</div><div class="headerCellMonth" style="width:126.42890508110469px">May</div>
<div class="headerCellMonth" style="width:122.35055330429486px">June</div>
<div class="headerCellMonth" style="width:126.42890508110469px">July</div><div class="headerCellMonth" style="width:126.42890508110469px">August</div>
<div class="headerCellMonth" style="width:122.35055330429486px">September</div>
<div class="headerCellMonth" style="width:126.42890508110469px">October</div>
<div class="headerCellMonth" style="width:122.35055330429486px">November</div>
<div class="headerCellMonth" style="width:126.42890508110469px">December</div>
</div>
</div>
<div class="container">
<div class="timelineContainer" style="width: 1503px;"></div>
</div>
<div class="container gantShow" data-group="Integrated Planning">
<div class="timelineContainer child" style="width: 1503px;">
<div class="timeline" style="width:722.9598440425635px;margin-left:772.560202716214px" title="2013/07/08 - 2013/12/31<br></div>Integrated Planning" onclick="onTimelineClick(this)" data-id="159c5c97-c135-4906-970c-e4d58f647c41" data-startdate="2013/07/08">100%</div>
</div>
</div>
<div class="container gantShow" data-group="Integrated Planning">
<div class="timelineContainer child" style="width: 1503px;">
<div class="timeline" style="width:949.2691917671041px;margin-left:546.2508549916735px" title="2013/05/14 - 2013/12/31<br></div>Integrated Planning" onclick="onTimelineClick(this)" data-id="5c3756b1-0674-4bfc-b6ce-fa765db63eed" data-startdate="2013/05/14">100%</div>
</div>
</div>
Here is my console log: 这是我的控制台日志:
LOG: collapseClick on group:Integrated Planning 日志:崩溃单击组:集成计划
LOG: obj class before:leftcollapse toggleMinus 日志:obj类之前:左合拢toggleMinus
LOG: obj class after:leftcollapse toggleExpand LOG:之后的obj类:leftcollapse toggleExpand
LOG: div loop for group:Integrated Planning index:0 日志:组:综合计划索引div循环:0
LOG: div loop for group:Integrated Planning index:1 日志:组:集成计划索引:1的div循环
LOG: div loop for group:Integrated Planning index:2 日志:组的div循环:综合计划索引:2
LOG: div loop for group:Integrated Planning index:3 日志:组:集成计划索引:3的div循环
I really need help this IE8 problem begin to annoyed me a lot... 我真的需要帮助,这个IE8问题开始让我很烦。
ANSWER: 回答:
I've found the answer to my question. 我找到了我问题的答案。
The problem was related with how chrome and IE handle the resize event. 问题与chrome和IE如何处理resize事件有关。
I had another javascript function that was called on the resize of the browser ( 我在浏览器调整大小时调用了另一个JavaScript函数(
$(window).resize(function () {
console.log("resize");
config.zoomLevel = ($(window).width() - 200) / 421.739; //magic formula to know how many pixel is entering in the screen for the chart.
createGantControl(('#' + mainControlId), config);
});
). )。
This function was regenerating my graph. 此函数正在重新生成我的图形。
Hope it can help in the futur! 希望对未来有所帮助!
-Jeff -Jeff
I've found the answer to my question. 我找到了我问题的答案。
The problem was related with how Chrome and IE handle the resize
event. 问题与Chrome和IE如何处理
resize
事件有关。
I had another JavaScript function that was called on the resize of the browser: 我在浏览器调整大小时调用了另一个JavaScript函数:
$(window).resize(function () {
console.log("resize");
//magic formula to know how many pixel is entering in the screen for the chart
config.zoomLevel = ($(window).width() - 200) / 421.739;
createGantControl(('#' + mainControlId), config);
});
This function was regenerating my graph. 此函数正在重新生成我的图形。
resize
event. resize
事件。 resize
event so my graph was always rerender. resize
事件,因此我的图形总是被重新渲染。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.