当前位置: 代码迷 >> 综合 >> js childNodes 在傲游浏览器下的表现真诡异
  详细解决方案

js childNodes 在傲游浏览器下的表现真诡异

热度:61   发布时间:2023-12-08 13:59:49.0

今天做页面的时候要写一个遍历某节点下所有子节点的方法,在IE下一切正常,到遨游的极速模式下就没反应了,

跟踪了半天,是因为遨游下,执行  ctl.parentElement.childNodes 这个对象,找到 33 个子节点,而IE下只找到16个,查看源文件,也只有16个节点,

遨游真TM垃圾啊。。。 用 alert(); 跟踪这33个节点,除了正常的16的节点外,还多出了 17 个 undefine 节点,操。

找到原因就再写个循环把这些莫名多出来的垃圾清理掉就OK了。

<div class="week_ph"><div class="week_ph_head">其他顾客正在看</div><div class="week_ph_k"><div class="week_ph_css1" style='display:block;'><div class="week_ph_num"><img src='/images/jfsc/jifeng_con_1.jpg' width="12"height="12" /></div><div class="week_ph_pic"><a href='/products.aspx?spid=8141' title='LG LW4500电视 42LW4500 42寸' target="_blank"><img src='http://img.nnbh.cn/NNBH/goods_new/00/00/81/8141-MS-1.jpg' width="60" height="60" /></a></div><div class="week_ph_wrod"><div class="week_ph_h"><a href='/products.aspx?spid=8141' title='LG LW4500电视 42LW4500 42寸' target="_blank">LG LW4500电视 42LW4500 42寸</a></div><div class="week_ph_l">?7499.00</div></div></div><div οnmοusemοve='spweekMouseover(this,1)' class="week_ph_css2"style='display:none;'><div class="week_ph_num2"><img src='/images/jfsc/jifeng_con_1.jpg' width="12"height="12" /></div><div class="week_ph_h2"><a href='/products.aspx?spid=8141' title='LG LW4500电视 42LW4500 42寸' target="_blank">LG LW4500电视 42LW4500 42寸</a></div></div>            </div>
</div>          


    var forEach = function(array, callback, thisObject) {if (array.forEach) {array.forEach(callback, thisObject);} else {for (var i = 0, len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); }}}function spweekMouseover(ctl, n) {var arrayObj = new Array();forEach(ctl.parentElement.childNodes, function(o, i) {if (o.tagName == 'DIV')arrayObj.push(o);});forEach(arrayObj, function(o, i) {if ((n == (Math.floor(i / 2) + 1) && i % 2 == 0) || (n != (Math.floor(i / 2) + 1) && i % 2 != 0)) {o.style.display = "block";} else {o.style.display = "none";}});        }