2

我在我的页面上使用了 jHtmlArea jQuery 插件,并且我在点击按钮时让它可见。现在我试图将焦点放在 jHtmlArea 编辑器中,一旦它显示出来,但似乎无法到达那里。

我确实找到了这篇博客文章Setting Focus to Control in an IFRAME using jQuery讨论将焦点设置到 IFrame 内的元素,thickbox 插件通过先将焦点设置到 IFrame 然后再设置到元素来使用该元素,但是 jHTMLArea 没有放置将任何元素放入其 IFrame。

所以要么我没有正确选择 IFrame 的 body 元素,要么调用.focus()body 对我没有任何作用。

这是 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();
}

感谢您提供的任何帮助。

4

1 回答 1

3

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

于 2009-12-21T07:27:14.317 回答