jquery insertAfter for ie8 [英] jquery insertAfter for ie8
问题描述
var attachmentDeleteMainModal = $('#attachment-deletion');
var attachmentDeleteMainModalClone = attachmentDeleteMainModal.clone();
attachmentDeleteMainModalClone.attr('id', 'attachment-deletion-'+'main');
attachmentDeleteMainModalClone.insertAfter('#attachment-deletion');
此方法在Chrome中将我的新选择器添加到DOM中,但在ie8中不起作用,这是我目前测试的全部
This method adds my new selector to the DOM in Chrome, but does not work in ie8, this is all I tested so far
append
而不是 insertAfter
不会在任一浏览器中创建所需的选择器.但是在 ie8 中它根本不创建任何东西
append
instead of insertAfter
does not create the desired selector in either browser. But in ie8 it does not create anything at all
有什么办法解决这个问题?任何见解表示赞赏
what is the solution to this? any insight appreciated
推荐答案
在 IE8 中,我在 $rows.insertAfter($(elem)) 行中有一个异常,所以我用这个解决方案修复了它:
In IE8 I had an exception in $rows.insertAfter($(elem)) line, so I fixed it with this solution:
var $rows = $("tr", $(parsedXML));
try {
$rows.insertAfter($(elem));
} catch (error) {
// we got <table><tbody><tr... from the server and need to paste only all <tr> from it after our tr in $(elem)
var divData = $("table", $(parsedXML));
var divTmp = document.createElement("div");
divTmp.innerHTML = divData[0].xml;
var children = divTmp.firstChild.firstChild;
var fragment = document.createDocumentFragment();
var current = children.firstChild;
while (current) {
fragment.appendChild(current.cloneNode(true));
current = current.nextSibling;
}
elem.parentNode.insertBefore(fragment, elem.nextSibling);
}
对不起,.firstChild.firstChild"不是那么干净,但对我有用.我们从服务器获得了 Sorry, it is not so clean with ".firstChild.firstChild", but worked for me.
We got 这篇关于jquery insertAfter for ie8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 之后粘贴 代码>$(elem)
<table><tbody><tr...
from the server and need to paste only all <tr>
from it after our tr in $(elem)
登录
关闭