大佬们,你看下我代码注释的部分,为什么第二个弹出的是false,而第四个弹出true,不是应该弹出的是true么?能指点一下么??我现在要判断无论是当前页面的document还是iframe的document都返回true怎么判断??
- HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TEST</title> <script type="text/javascript"> window.onload = function () { var doc = document.getElementById("mainFrame").contentWindow.document; alert(doc); // 弹出 [object HTMLDocument] alert(doc instanceof HTMLDocument); // 弹出false alert(document); // 弹出 [object HTMLDocument] alert(document instanceof HTMLDocument); // 弹出true } </script> </head> <body> <iframe id="mainFrame" src="test1.htm"></iframe> </body> </html>
------解决方案--------------------
怎么会弹出[object HTMLDocument]
应该是[object Document]
而且alert(doc instanceof Document);
------解决方案--------------------
我两次都弹出的[object HTMLDocument]
而且两次都是true啊 火狐测得
ie9报错