开发者

jHtmlArea event handling of keypress

I'm currently developping a text-to-symbol conversion tool (non-profit), and I'm having this problem:

For the WYSIWYG-editting of the text, I'd like to use a nice small wysiwyg editor (like jHtmlArea). This editor will show floating divs, so I'll have to intercept a lot of keypresses (spaces/arrows/etc)

Currently, my html area is loaded like this:

<script type="text/javascript">    
$(function() {
            $("#txtCustomHtmlArea").htmlarea({
                 loaded: function() {
                 $(this.editor).keydown(function(event) { 
                     if(event.keyCode == 32) {
                         this.pasteHTML('<b>test</b>');
          开发者_JAVA百科               return false;
                     }

                     return true;
                });
            }

The problem with this code is that this.editor doesn't have the method pasteHTML. How can I use this method from this(=htmlarea).event?

This is most probably a fairly beginner question, but I'm really clueless towards where to look.

Thank you


Here's how I do it:

    $("#my-text-area").htmlarea({
        loaded: function () {
            $.myControl = { jhtmlarea: this };
        }
    });

Then I can reference:

$($.myControl.jhtmlarea.editor.body).keypress(function (e) { });

This also gives me a handle to my the html area object from outside of the iFrame.


I think you're maybe getting yourself confused with the use of 'this' (I am definitely struggling to keep track of what it refers to!).

As a test, can you replace the

this.pasteHTML(...)

with

$("#txtCustomHtmlArea").pasteHTML(...)

or maybe

$("#txtCustomHtmlArea").editor.pasteHTML(...)

and see if that helps?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜