开发者

Firefox onkeypress event not passing in event parameter

I have the following textarea HTML tag that I am inserting a runtime into the DOM (I have only shown how it looks after it is inserted) and I'm set the onkeypress event to fire as an inline attribute. However, in Firefox I get an "event is not defined" error when I press a key went it is in focus.

<textarea rows="3" cols="70" type="text" name="resultsRename" value="" class="redlining_textContent_Dialog_textbox" dojoType="dijit.forms.SimpleTextArea" id="labelText" propercase="false" style="width:auto;" onkeypress="return handleEnterKey(event,doFunc();">

function handleEnterKey(e, func)
{
    //alert("hit key handler");
    //alert(dojo.toJson(e));
    var key = e.keyCode || e.which;
    if (key == 13)
    {
        func();
        return false;
    }
    else
    {
        return true;
    }

}

I have looked at tons of help telling me that I should expect an event object parameter to be available to the js code I place in the onkeypress attr, but I keep getting this error.

The textarea tag is not inside a pair of form tags (I saw somewhere that this can be an issue sometimes but I have no choice here).

I have tried a handleEnterKey function with only the e parameter but this makes no difference.

If I change the inline attribute to...

onkeypress="return handleEnterKey(this,doFunc();"

... I enter 开发者_运维知识库the handleEnterKey with my e parameter set to the textarea object. Why Am I not being passed the event object? Obviously this works fine in IE with it's global event object.

At my wits end. Help me Stack Overflow... you're my only hope!


handleEnterKey should not even be called as you have a syntax error.

return handleEnterKey(event,doFunc();

should be

return handleEnterKey(event,doFunc);

Passing event definitely works: DEMO

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜