关于Javascript getElementsByTagName方法的问题

时间:2011-07-18 14:14:18

标签: javascript

我在我的一个iframe中设置了一个按钮的onclick事件处理程序,以便向内容添加内容 同一个窗口的另一个iframe表,我用

var w = parent.frames[1].getElementsByTagName("tr"); 

这个函数应该返回一个类似于数组的对象的HTMLcollection对象,但似乎firefox和chrome无法解析我的代码,因为它无法执行

alert("here") ;

我放置了getelement指令后,有没有人知道出了什么问题,我是Web编程新手......

2 个答案:

答案 0 :(得分:6)

该函数为getElementsByTagName("tag");,带有's'。

答案 1 :(得分:0)

您需要一个文档对象

" iframe.contentDocument" Not Working in IE8 and FF(3.5 and below) any other steps to solve this?

var doc;
var iframeObject = parent.document.getElementById('iframeID'); // MUST have an ID
if (iframeObject.contentDocument) { // DOM
  doc = iframeObject.contentDocument;
} 
else if (iframeObject.contentWindow) { // IE win
  doc = iframeObject.contentWindow.document;
}
if (doc) {
  var rows = doc.getElementsByTagName("tr");
}
else {
  alert('Wonder what browser this is...'+navigator.userAgent);
}

假设相同的域

相关问题