Javascript 在ie8中强制使用dom重新渲染器
我尝试了所有经典的ie技巧,让我的网页重新呈现在dom中所做的更改,但没有任何效果。我已经试过了Javascript 在ie8中强制使用dom重新渲染器,javascript,ajax,dom,internet-explorer-8,xmlhttprequest,Javascript,Ajax,Dom,Internet Explorer 8,Xmlhttprequest,我尝试了所有经典的ie技巧,让我的网页重新呈现在dom中所做的更改,但没有任何效果。我已经试过了 element.className = element.className; 以及访问我更改的dom的某些部分,但这也不起作用 这是我的密码。Onload主体调用queryDB,在html中有一个id为“plants”的段落。到目前为止,这段代码只能在Firefox3和chrome上正常工作 var timeout = 5000; //get new plants every 5 seconds
element.className = element.className;
以及访问我更改的dom的某些部分,但这也不起作用
这是我的密码。Onload主体调用queryDB,在html中有一个id为“plants”的段落。到目前为止,这段代码只能在Firefox3和chrome上正常工作
var timeout = 5000; //get new plants every 5 seconds
function queryDB() {
responseDoc = getXMLFrom("ajax/getallplants.php");
paragraph = document.getElementById("plants");
table = document.createElement("table");
table.setAttribute("class", "viewTable");
//clean up the last query
cleanUpLastResult(paragraph);
//loop through the responseDoc and dynamically add plants
if(plantsFound(responseDoc)) {
for(i = 0; i < responseDoc.documentElement.childNodes.length; i++) {
currentChild = responseDoc.documentElement.childNodes[i];
row = document.createElement("tr");
//old way of printing where the whole sci name and common name was just text
/*paragraph.appendChild(document.createTextNode(responseDoc.documentElement.childNodes[i].firstChild.nodeValue));
paragraph.appendChild(document.createElement("br"));*/
//newer way of printing where the common name is bolded
/*paragraph.appendChild(document.createTextNode(currentChild.firstChild.nodeValue + " "));
commonName = document.createElement("b");
commonName.appendChild(document.createTextNode(currentChild.getAttribute("commonname")));
paragraph.appendChild(commonName);
paragraph.appendChild(document.createElement("br"));*/
//newest way of printing that prints to a table
col1 = document.createElement("td");
col1.setAttribute("class", "viewTable");
col1.appendChild(document.createTextNode(currentChild.firstChild.nodeValue));
col2 = document.createElement("td");
col2.setAttribute("class", "viewTable");
col2Bold = document.createElement("b");
col2Bold.appendChild(document.createTextNode(currentChild.getAttribute("commonname")));
col2.appendChild(col2Bold);
row.appendChild(col1);
row.appendChild(col2);
table.appendChild(row);
}
paragraph.appendChild(table);
paragraph.className = paragraph.className;
paragraph.firstChild.className = paragraph.firstChild.className;
}
else {
paragraph.appendChild(document.createTextNode("no plants currently entered"));
}
//re-add the callback
setTimeout(queryDB, timeout);
}
function plantsFound(responseDoc) {
if(responseDoc.documentElement == null) {
return false;
}
else {
if(responseDoc.documentElement.firstChild.nodeType == 3) {
//text node so no children
return false;
}
else {
return true;
}
}
}
function cleanUpLastResult(paragraph) {
//old way of cleaning up where everything was only a childnode of the paragraph
/*while(paragraph.childNodes.length >= 1) {
paragraph.removeChild(paragraph.firstChild);
}*/
/* The three possible cases:
* 1 first execution time so paragraph has no child
* 2 nth execution time but nothing was found in db so only a textnode
* 3 nth execution and there's a whole table to clean up
*/
if(paragraph.firstChild == null) {
//nothing there so nothing to delete
}
else if(paragraph.firstChild.nodeValue != null) {
//no table printed, just remove that text node
paragraph.removeChild(paragraph.firstChild);
}
else {
//delete the whole table
table = paragraph.firstChild;
//remove each row
while(table.childNodes.length >= 1) {
//remove the two columns in it and their stuff
row = table.firstChild;
col1 = row.firstChild;
col2 = row.lastChild;
//remove column1 and it's text node
col1.removeChild(col1.firstChild);
row.removeChild(row.firstChild);
//remove column2, it's bold node and its text node
col2.firstChild.removeChild(col2.firstChild.firstChild);
col2.removeChild(col2.firstChild);
row.removeChild(row.firstChild);
table.removeChild(row);
}
//finally delete the table
paragraph.removeChild(paragraph.firstChild);
}
}
function getXMLFrom(url) {
if(window.XMLHttpRequest) {
//regular browser
xmlhttp = new XMLHttpRequest();
}
else {
//ie6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", url, false);
xmlhttp.send();
responseDoc = xmlhttp.responseDoc;
if(responseDoc == null) {
if(window.XMLHttpRequest && (typeof DOMParser != "undefined")) {
//firefox
var parser = new DOMParser();
responseDoc = parser.parseFromString(xmlhttp.responseText, "text/xml");
}
else {
//ie6 or ie7
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = true;
doc.loadXML(xmlhttp.responseText);
responseDoc = doc;
}
if(responseDoc == null) {
alert("error in parser xml from: " + url);
}
return responseDoc;
}
}
var超时=5000//每5秒换一株新植物
函数queryDB(){
responseDoc=getXMLFrom(“ajax/getallplants.php”);
段落=document.getElementById(“植物”);
table=document.createElement(“表”);
setAttribute(“类”、“视图表”);
//清理最后一个查询
cleanuplestresult(第段);
//在responseDoc中循环并动态添加植物
如果(plantsFound(responseDoc)){
对于(i=0;i=1){
第1.2段(第1.2段);
}*/
/*三种可能的情况:
*1第一次执行时间,因此段落没有子段落
*第2次执行,但在数据库中找不到任何内容,因此只有一个textnode
*第三次执行,还有一整张桌子要清理
*/
如果(段落.firstChild==null){
//没有,所以没有要删除的内容
}
else if(段落.firstChild.nodeValue!=null){
//不打印表格,只需删除该文本节点即可
第1.2段(第1.2段);
}
否则{
//删除整个表
表=第1.1段;
//删除每一行
while(table.childNodes.length>=1){
//删除其中的两列及其内容
行=table.firstChild;
col1=row.firstChild;
col2=row.lastChild;
//删除column1及其文本节点
col1.removeChild(col1.firstChild);
row.removeChild(row.firstChild);
//删除第2列,它的粗体节点及其文本节点
col2.firstChild.removeChild(col2.firstChild.firstChild);
col2.removeChild(col2.firstChild);
row.removeChild(row.firstChild);
表2.removeChild(世界其他地区);
}
//最后删除表
第1.2段(第1.2段);
}
}
函数getXMLFrom(url){
if(window.XMLHttpRequest){
//常规浏览器
xmlhttp=新的XMLHttpRequest();
}
否则{
//ie6
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
open(“GET”,url,false);
xmlhttp.send();
responseDoc=xmlhttp.responseDoc;
if(responseDoc==null){
if(window.XMLHttpRequest&(typeof DOMParser!=“未定义”)){
//火狐
var parser=新的DOMParser();
responseDoc=parser.parseFromString(xmlhttp.responseText,“text/xml”);
}
否则{
//ie6或ie7
var doc=新的ActiveXObject(“Microsoft.XMLDOM”);
doc.async=true;
doc.loadXML(xmlhttp.responseText);
responseDoc=doc;
}
if(responseDoc==null){
警报(“解析器xml中的错误来自:“+url”);
}
返回响应DOC;
}
}
我还测试了responseDoc,我知道我从getallplants.php得到了正确的响应,它生成了各种植物的xml表示。有没有办法解决这个问题?另外,由于各种原因,我不能使用JQuery来实现这一点
编辑我在另一个SO线程上找到了一个准好的解决方案。如果我添加document.write(document.all[0].innerH