我的页面里面有个Iframe,如何让页面初始时获得鼠标的焦点呢?代码如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!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 runat="server">
<title></title>
</head>
<body style="margin: 0px; padding: 0px" link="#0000ff" >
<iframe id="showValue" style="text-align: left; margin: 0px; padding: 0px;" frameborder="no"
scrolling="yes" width="100%" height="98px"></iframe>
<script type="text/javascript">
window.onload = function () {
document.getElementById("showValue").contentWindow.document.write("<html><body style='margin:0px;color:<%=color %>;font-size:<%=size %>px;font-family:<%=font %>;word-spacing:5px;letter-spacing:2px;padding:0px;margin:0px; line-height:20px;z-index:100;background:#fff;left:0;top:0;work-wrap:break-word;overflow:hidden' scrolling='no' onload='this.height=showValue.document.body.scrollHeight+20'></body></html>");
document.getElementById("showValue").contentWindow.document.designMode = "on";
document.getElementById("showValue").contentWindow.document.contentEditable = true;
document.getElementById("showValue").focus();
}
</script>
</body>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="margin: 0px; padding: 0px" link="#0000ff" >
<iframe id="showValue" style="text-align: left; margin: 0px; padding: 0px;" frameborder="no"
scrolling="yes" width="100%" height="98px"></iframe>
<script type="text/javascript">
window.onload = function () {
document.getElementById("showValue").contentWindow.document.write("<html><body style='margin:0px;color:<%=color %>;font-size:<%=size %>px;font-family:<%=font %>;word-spacing:5px;letter-spacing:2px;padding:0px;margin:0px; line-height:20px;z-index:100;background:#fff;left:0;top:0;work-wrap:break-word;overflow:hidden' scrolling='no' onload='this.height=showValue.document.body.scrollHeight+20'></body></html>");
document.getElementById("showValue").contentWindow.document.designMode = "on";
document.getElementById("showValue").contentWindow.document.contentEditable = true;
document.getElementById("showValue").focus();
}
</script>
</body>
</html> 展开
展开全部
JS不行也可以考虑在.cs文件里面写focus();
更多追问追答
追问
在C#里也写过了,我在WebBrowser加载完毕以后写的,也是不行
private void webBroContent_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBroContent.Document.Body.KeyDown += new HtmlElementEventHandler(webBroContent_KeyDown);
webBroContent.Document.Window.Frames["showValue"].Focus();
}
追答
showValue是iframe就算得到焦点你又如何知道,要不就直接把焦点放在iframe里面的某个控件里
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询