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();
}
感謝你可以通過任何幫助。
這在大多數正常情況下都能正常工作,唯一的問題是我想讓jHtmlArea出現在模態中,並在模態被打開時獲得焦點。 我的解決辦法 $( 「#BtnToggleDescriptionDisplay」)點擊(函數(E){ e.preventDefault(); $( 「#descriptionHtmlEntry」)切換(); window.setTimeout('$(」 iframe「)[0] .contentWindow.focus()',30); }); – Billyhole 2010-03-02 18:53:25