帮助DOM和IE [英] help with DOM and IE
问题描述
我无法弄清楚为什么下面的函数在IE 6中没有做任何事情。
我将表的id传递为which。变量。当我激活
函数时,没有任何反应。它没有返回任何错误。
这在Firefox中运行得非常好 - 一个新的表格行显示一个包含文本
表格的单元格。嗨那里。
有人可以就此给出一些建议吗?
谢谢!
N
函数ieTest(which){
var objTmp1 = document.createElement(" td");
objTmp1.appendChild(document。 createTextNode(" Hi there"));
objTmp1.setAttribute(" colspan",5);
var objTmp2 = document.createElement(" tr") ;
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2);
window.alert(document。 getElementById(which).getAtt ribute(" cellpadding"))
}
I can''t figure out why the function below isn''t doing anything in IE 6.
I pass the id of a table as the "which" variable. When I activate the
function, nothing happens. It doesn''t return any errors.
This works perfectly fine in Firefox - a new table row appears with a
table cell containing the text "Hi there".
Can anyone give some advice on this?
Thanks!
N
function ieTest(which) {
var objTmp1 = document.createElement("td");
objTmp1.appendChild(document.createTextNode("Hi there"));
objTmp1.setAttribute("colspan",5);
var objTmp2 = document.createElement("tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2 );
window.alert(document.getElementById(which).getAtt ribute("cellpadding"))
}
推荐答案
alMIGHTY N写道:
The alMIGHTY N wrote:
我不知道为什么下面这个函数在我做什么都没有E 6.
我将表的id传递为which表。变量。当我激活
功能时,没有任何反应。它没有返回任何错误。
这在Firefox中完全正常 - 出现一个新的表格行,其中包含一个包含文本Hi there的表格单元格。
任何人都可以给出一些建议吗?
谢谢!
$
函数ieTest(which){
var objTmp1 = document.createElement(" td");
objTmp1.appendChild(document.createTextNode(" Hi there"));
objTmp1.setAttribute(" colspan",5);
var objTmp2 = document.createElement(" tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2);
window.alert( document.getElementById(which).getAtt ribute(" cellpadding"))
}
I can''t figure out why the function below isn''t doing anything in IE 6.
I pass the id of a table as the "which" variable. When I activate the
function, nothing happens. It doesn''t return any errors.
This works perfectly fine in Firefox - a new table row appears with a
table cell containing the text "Hi there".
Can anyone give some advice on this?
Thanks!
N
function ieTest(which) {
var objTmp1 = document.createElement("td");
objTmp1.appendChild(document.createTextNode("Hi there"));
objTmp1.setAttribute("colspan",5);
var objTmp2 = document.createElement("tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2 );
window.alert(document.getElementById(which).getAtt ribute("cellpadding"))
}
使用insertRow(-1)和insertCell(-1)创建和添加行和单元格。
var row = document.getElementById(which).insertRow(-1);
var cell = row.insertCell(-1) ;
.....
-
Ian Collins。
Use insertRow(-1) and insertCell(-1) to create and add the row and cell.
var row = document.getElementById(which).insertRow(-1);
var cell = row.insertCell(-1);
.....
--
Ian Collins.
alMIGHTY N在5/1/2006 4:39 AM说了以下内容:
The alMIGHTY N said the following on 5/1/2006 4:39 AM:
我可以我们弄清楚为什么下面的函数在IE 6中没有做任何事情。
我将表的id传递为which。变量。当我激活
功能时,没有任何反应。它没有返回任何错误。
这在Firefox中完全正常 - 一个新的表格行显示一个
表格单元格,其中包含文本Hi there。
在这种情况下,Firefox实际上是错了。
有人可以给出一些建议吗?
谢谢!
$
函数ieTest(which){
var objTmp1 = document.createElement(" td");
objTmp1.appendChild(document.createTextNode) (你好));
objTmp1.setAttribute(" colspan",5);
不要在IE中使用setAttribute,众所周知它是错误的。
objTmp1.colspan =" 5";
var objTmp2 = document.createElement(" tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2);
你不能将孩子附加到IE中的Table元素,你必须将它附加到TBODY
。在这方面,基于Mozilla的浏览器弄错了。
window.alert(document.getElementById(which).getAtt ribute(" cellpadding"))
I can''t figure out why the function below isn''t doing anything in IE 6.
I pass the id of a table as the "which" variable. When I activate the
function, nothing happens. It doesn''t return any errors.
This works perfectly fine in Firefox - a new table row appears with a
table cell containing the text "Hi there".
In this case, Firefox is actually getting it wrong.
Can anyone give some advice on this?
Thanks!
N
function ieTest(which) {
var objTmp1 = document.createElement("td");
objTmp1.appendChild(document.createTextNode("Hi there"));
objTmp1.setAttribute("colspan",5);
Don''t use setAttribute with IE, it is known to be buggy.
objTmp1.colspan = "5";
var objTmp2 = document.createElement("tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2 );
You can''t appendChild to the Table element in IE, you have to append it
to a TBODY. In that regards, Mozilla based browsers get it wrong.
window.alert(document.getElementById(which).getAtt ribute("cellpadding"))
>
您也可以直接访问属性:
alert(document.getElementById(which).cellpadding);
- -
兰迪
comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周
Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /
You can access the attributes directly also:
alert(document.getElementById(which).cellpadding);
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
非常感谢!我很惊讶Firefox会得到一些东西
错误...当然,我可能应该早先测试IE很多
。
再次感谢!
Great thanks! I''m surprised that Firefox would have gotten something
wrong... of course, I probably should have tested with IE a lot
earlier.
Thanks again!
这篇关于帮助DOM和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!