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

请看下面的代码,解释在点DIV导致IFRAME失去焦点的原因及提供解决方法[除指定文字或图片的ONCLICK]
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>
</head>

<body>
<iframe   frameborder= "1 "   id= "editor_iframe "   name= "editor_iframe "   scrolling= "auto "   width= "100% "   height= "200 "   align= "center "> </iframe>
<input   type= "button "   value= "添加文字 "   onclick= "FormatText( 'bold ') "/>
<div   style= "height:20px;width:50px;margin-left:50px;   background-color:#0099CC "   onclick= "FormatText( 'bold ') "> </div>
<script>
var   iFrame   =   frames[ "editor_iframe "];
var   bodyTag= " <html> <head> <style   type=text/css> body{font-size:12px;} </style> </head> <BODY   bgcolor=\ "#FFFFFF\ "   > ";
iFrame.document.open();
iFrame.document.write(bodyTag);
iFrame.close();
iFrame.document.designMode= "On ";
iFrame.focus();
function   FormatText(command)
{
iFrame.document.execCommand(command,   false,   null);
iFrame.focus();
}
</script>
</body>
</html>


------解决方案--------------------
谁看懂了说一声!