日期:2014-05-16  浏览次数:20357 次

我这个例子在firefox里为什么不能显示呀
<script name=script1>
function checkall()
{
  var owin=window.open("","_blank");
  owin.document.write("下面的内容在ie8中可以显示,在firefox9中不可以,不知道为什么");
  owin.document.write(document.images("img1").src+"<br>");
  owin.document.write(document.images.item("img2").src+"<br>");
  var objImg=document.images.item("sample");
  if(objImg!=null)
  {
  if(objImg.length!=null)
  {
  for(var i=0;i<objImg.length;i++)
  {
  owin.document.write(objImg[i].src+"<br>");  
  }
  }
  }
}
</script>
<body onload="checkall()">
<img src="sample1.gif" name=sample id=img1>
<img src="sample2.gif" name=sample id=img2>
</body>

------解决方案--------------------
dom元素的选择方式不一样吧
------解决方案--------------------
用谷歌试试
------解决方案--------------------
Uncaught TypeError: Property 'images' of object #<HTMLDocument> is not a function

document.images( 没这个方法
------解决方案--------------------
嗯 是的 也遇到了 一直不知道怎么解决 可能是不同的浏览器对安全因素的考虑不同所致吧
------解决方案--------------------
owin.document.write(document.images["img1"].src+"<br>");
var objImg=document.images["sample"];
------解决方案--------------------
用 getElementById
或者 getElementsByTagName