将焦点设置为 jHtmlArea jQuery 插件
我在页面上使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)