-5

这是代码

<html>
    <head>
        <script language="JavaScript">
        <!--
            function myFunc() {
            var doc = parent.frames[1].document;
            doc.open();
            doc.write(<html><body class="dialogBody"><form><table width="100%"><tr class="colHeader" width="100%"><td align=left valign=middle>&nbsp;</td><td height=20px align=left valign=middle>Cell2</td></tr><tr class=normalRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name='select' value=0/></td><td height=20px align=left valign=middle>Ed</td></tr><tr class=altRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name='select' value=1/></td><td height=20px align=left valign=middle>Ed2</td></tr></table></form></body></html>);
            doc.close();
            }
            var topFrame = "<a href='#' " +"onClick='parent.myFunc()'>Click me</a>";
            var botFrame = ""; 
            myFunc(); 
        //-->
        </script>
    </head>
    <frameset rows="50%,*">
    <frame src="javascript:parent.topFrame"><input type="button" value="Click me!" onclick="myFunc()" /></frame>
    <frame src="javascript:parent.botFrame">
    </frameset>

</html>

使用 Safari 或 firefox 加载此代码时显示空白。你能猜到为什么吗?

4

2 回答 2

4

用引号括起来,应该可以工作:

 doc.write('<html><body class="dialogBody"><form><table width="100%"><tr class="colHeader" width="100%"><td align=left valign=middle>&nbsp;</td><td height=20px align=left valign=middle>Cell2</td></tr><tr class=normalRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name=\'select\' value=0/></td><td height=20px align=left valign=middle>Ed</td></tr><tr class=altRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name=\'select\' value=1/></td><td height=20px align=left valign=middle>Ed2</td></tr></table></form></body></html>');
于 2012-05-10T03:55:57.137 回答
1

上的 HTML

doc.write(<html><body class="dialogBody"><form><table width="100%"><tr class="colHeader" width="100%"><td align=left valign=middle>&nbsp;</td><td height=20px align=left valign=middle>Cell2</td></tr><tr class=normalRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name='select' value=0/></td><td height=20px align=left valign=middle>Ed</td></tr><tr class=altRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name='select' value=1/></td><td height=20px align=left valign=middle>Ed2</td></tr></table></form></body></html>);

不是字符串。字符串中的引号需要转义。它最终看起来像这样:

doc.write("<html><body class=\"dialogBody\"><form><table width=\"100%\"><tr class=\"colHeader\" width="100%"><td align=left valign=middle>&nbsp;</td><td height=20px align=left valign=middle>Cell2</td></tr><tr class=normalRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name='select' value=0/></td><td height=20px align=left valign=middle>Ed</td></tr><tr class=altRow><td width=20 height=20px align=left valign=middle><input type=radio height=12px width=12px align =center vlign=middle name='select' value=1/></td><td height=20px align=left valign=middle>Ed2</td></tr></table></form></body></html>");
于 2012-05-10T03:55:09.927 回答