我在页面上使用了jHtmlArea jQuery插件,并使其在按钮的onClick上可见。现在,我试图将焦点显示在jHtmlArea编辑器中,但是似乎无法到达那里。
我确实找到了此博文Setting Focus to Control in an IFRAME using jQuery,该博文是关于将焦点设置到thickbox插件利用的IFrame中的元素上的,方法是先将焦点设置到IFrame,然后再设置到该元素,但是jHTMLArea不会将任何元素放入其IFrame中。
因此,要么我没有正确选择IFrame的body元素,要么对主体调用.focus()
对我没有任何帮助。
这是jHtmlArea生成的输出:
<div class="jHtmlArea" style="width: 498px;">
<div class="ToolBar" style="width: 496px;">
<ul>
... removed toolbar code for briefness
</ul>
</div>
<div>
<iframe style="height: 256px; width: 494px;">
<html>
<head>
<link rel="stylesheet" type="text/css" href="jHtmlArea.Editor.css"></link>
</head>
<body>
<br _moz_editor_bogus_node="TRUE" _moz_dirty=""/>
</body>
</html>
</iframe>
</div>
<textarea id="TxtAreaDescription" rows="15" cols="60" name="TxtAreaDescription" style="display: none;"/>
这是我尝试过的一些方法:
var iframe = $("iframe");
if (iframe != null) {
$(iframe).focus();
$(iframe).contents().find("body").focus();
}
多谢您的协助。
最佳答案
已加载:function(){
this.iframe [0] .contentWindow.focus();
}