将片段附加到节点不工作在ie7,但在ie8中工作
Appending a fragment to a node is not working in ie 7 but working in ie8
我使用以下代码将一些ul
和li
元素直接添加到DOM中。我正在使用一个片段,并将子节点附加到片段,最后将片段附加到节点。
function updateTree(objArray,leafClass){
var currentElement = document.getElementById(currentNodeId);
currentElement.setAttribute("class",'jstree-open jstree-unchecked');
var fragment = document.createDocumentFragment();
var ulElement = document.createElement('ul');
var i = objArray.length;
//LoopStart
for (var i = 0, j = objArray.length ; i < j; i++ ){
//while(i--){
var liElement = document.createElement('li');
liElement.setAttribute("id", objArray[i].attr.id);
liElement.setAttribute("class",'jstree-closed jstree-unchecked '+leafClass+'');
liElement.innerHTML = "<ins class='"jstree-icon'"> </ins><a href='"#'" class='"'"><ins class='"jstree-checkbox'"> </ins><ins class='"jstree-icon'"> </ins>" + objArray[i].data + "</a> ";
if(currentElement.getAttribute("class").indexOf('leaf') > 0){
ulElement.appendChild(liElement);
fragment.appendChild(ulElement);
//$(currentElement.childNodes[1]).removeClass('jstree-laoding');
//console.log("update Tree inside if: " + objArray[i].data);
return "OK";
}
ulElement.appendChild(liElement);
fragment.appendChild(ulElement);
//console.log("update Tree for : " + objArray[i].data);
//}
}
//LoopEnd
currentElement.appendChild(fragment.cloneNode(true));
currentElement.childNodes[1].setAttribute("class","");
//console.log("update Tree end: ");
////console.log("time"+timer.getDiff());
//$(currentElement.childNodes[1]).removeClass('jstree-laoding');
return "OK";
}
代码在IE8和Firefox中工作良好,但在IE7中,我无法看到我正在添加的元素;
我不确定,但我猜问题出在你的
if(currentElement.getAttribute("class").indexOf('leaf') > 0){
ulElement.appendChild(liElement);
fragment.appendChild(ulElement);
//$(currentElement.childNodes[1]).removeClass('jstree-laoding');
//console.log("update Tree inside if: " + objArray[i].data);
return "OK";
}
我试了一个简单的代码
<html><head><script>
function abc(){
alert(document.getElementById("a1").getAttribute("class"));
}
</script>
</head>
<body onload="abc();">
<div id="a1" class="ac"></div>
</body>
</html>
警报Ff -> acIe8 -> null-> null
解决方案:使用className
代替getAttribute- document.getElementById("a1").getAttribute("class") ->错误实施
- . getelementbyid (" a1 ")。
和if
块的使用比较突兀,希望您能根据您的使用情况检查一下。
相关文章:
- 应该怎么做才能使其在IE7中工作
- Chrome 中的图片映射:事件未触发!在IE7中工作正常
- 无法在 IE 9 中传递此运算符的值,而它在 IE7 和 IE8 中工作正常
- 使 JavaScript 特定的代码在 IE7 中工作
- 获取尾随逗号(在JavaScript中)在IE7 / IE8中工作
- jquery设置隐藏的输入值在IE7和IE8中未按预期工作
- 推文按钮在IE7中无法正确显示,但在Mozilla,chrome和IE 8中工作正常
- 为什么我的应用程序中的某些组件在IE7中工作,而在IE9中不起作用
- slideToggle()在IE7中无法正常工作
- 我可以使用excanvas或类似的画布填充程序让impact js在IE7和/或8中工作吗
- this.style.backgroundColor don'我不在IE7/8工作
- 让hashchange事件在所有浏览器(包括IE7)中工作
- 带有渐变的Javascript滑块在chrome上失败,而在FF和IE7/8/9上工作
- IE7中没有填充mootools中的动态下拉列表.IE8工作良好
- 水平菜单和具有公共边界的子菜单,它们也必须在ie7中工作
- jQuery:包含在ie7中不工作的内容(jQuery 1.3.5)
- jQuery Scroll不能在ie7和ie8中工作
- 美元(& # 39;html # 39;) .append()并# 39;t在IE7工作
- ie7问题:jquery点击编辑不工作
- 按钮标签在ie7中不工作