Use jQuery to resolve the difference between the createElement method under IE and FireFox
- 2020-03-29 23:44:32
- OfStack
When we need to generate DOM objects dynamically, we create them using the createElement method. But under IE and Firefox, the createElement method is different.
In IE, you can create an element in two ways:
1, the document. The createElement method (' table ')
2, the document. The createElement method (' < The table border = "0" > ')
Document. The createElement method (' table ')
Also, if you add attributes and events, you need to use the setAttribute method
Example:
if($.browser.msie){
var rowHtml = '<span class="ellipsis" onclick="';
rowHtml += '_showNotice(/'';
rowHtml += id
rowHtml += '/',/'';
rowHtml += titlePre;
rowHtml += '/')"';
rowHtml += ">";
rowHtml += "</span>";
row = $(document.createElement(rowHtml)).text(data.Title);
}else if($.browser.mozilla){
var el = document.createElement("span");
el.setAttribute("onclick","_showNotice(/'" + id + "/',/'" + titlePre +"/')");
row = $(el).text(data.Title);
}else if($.browser.safari){
}else if($.browser.opera){
}else{
}