2009-10-23 98 views
2

我在页面上使用jHtmlArea jQuery插件,并且使它在按钮上可见。现在,我试图在焦点显示在jHtmlArea编辑器中,但似乎无法实现。将焦点设置为jHtmlArea jQuery插件

我发现这个博客帖子Setting Focus to Control in an IFRAME using jQuery这是谈论焦点设置了ThickBox的插件使用,届时将焦点设置到IFrame的第一个元素中的iframe内的元素,但jHTMLArea不放置任何内容纳入其iframe中。

所以要么我没有正确选择IFrame的身体元素或呼叫.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(); 
} 

感谢你可以通过任何帮助。

回答

3

loaded:function(){ this.iframe [0] .contentWindow.focus(); }

+0

这在大多数正常情况下都能正常工作,唯一的问题是我想让jHtmlArea出现在模态中,并在模态被打开时获得焦点。 我的解决办法 $( “#BtnToggleDescriptionDisplay”)点击(函数(E){ e.preventDefault(); $( “#descriptionHtmlEntry”)切换(); window.setTimeout('$(” iframe“)[0] .contentWindow.focus()',30); }); – Billyhole 2010-03-02 18:53:25