将焦点设置为 jHtmlArea jQuery 插件

发布于 2024-08-09 07:35:38 字数 1392 浏览 1 评论 0原文

我在页面上使用 jHtmlArea jQuery 插件,并使其在单击按钮时可见。现在,我试图在 jHtmlArea 编辑器显示后将焦点放入其中,但似乎无法到达那里。

我确实找到了这篇博客文章 使用 jQuery 将焦点设置到 IFRAME 中的控件,它讨论的是通过首先将焦点设置到 IFrame,然后设置到元素,但 jHTMLArea 不会将任何元素放入其 IFrame 中。

因此,要么我没有正确选择 IFrame 的 body 元素,要么对 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();
}

感谢您提供的任何帮助。

I'm using the jHtmlArea jQuery plugin on my page and I'm making it visible onClick of a button. Now I'm trying to place the focus into the jHtmlArea editor once it's displayed, but just can't seem to get there.

I did find this blog post Setting Focus to Control in an IFRAME using jQuery which is talking about setting focus to an element inside the IFrame that the thickbox plugin utilizes by setting focus to the IFrame first then to the element, but jHTMLArea doesn't place any elements into its IFrame.

So either I'm not properly selecting the IFrame's body element or calling .focus() to the body is doing nothing for me.

Here's the output that jHtmlArea is generating:

<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;"/>

Here's some of what I've tried:

var iframe = $("iframe");
if (iframe != null) {
    $(iframe).focus();
    $(iframe).contents().find("body").focus();
}

Thanks for any help you can pass on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悸初 2024-08-16 07:35:38

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文