为了清晰起见,下面用最简单的HTML和JavaScript来说明。有这么一段HTML(head部分是标准的head,doctype使用xhtml-transitional的DTD):
复制代码 代码如下:
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0">
<param value="https://www.jb51.net/Test.swf" />
<param value="high" />
<embed src="https://www.jb51.net/Test.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>
</object>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0">
<param value="https://www.jb51.net/Test.swf" />
<param value="high" />
<embed src="https://www.jb51.net/Test.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>
</body>
</object>
现在,我们分别用两种方式来获取第一个object(swf)的param参数个数:
复制代码 代码如下:
var o = document.getElementsByTagName('object')[0];
alert(o.getElementsByTagName('param').length);
alert(o.childNodes.length);
猜猜结果分别是什么?还有,再猜猜o.innerHTML是什么?大家可以自己试试。上面的结果分别是4和2,是不是很诡异?