admin管理员组文章数量:1023112
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 handleEnterKe
y 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!
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 handleEnterKe
y 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!
Share Improve this question edited Jun 24, 2021 at 11:07 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 5, 2011 at 15:13 MrGFunkMrGFunk 631 silver badge7 bronze badges1 Answer
Reset to default 4handleEnterKey
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
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 handleEnterKe
y 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!
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 handleEnterKe
y 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!
Share Improve this question edited Jun 24, 2021 at 11:07 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 5, 2011 at 15:13 MrGFunkMrGFunk 631 silver badge7 bronze badges1 Answer
Reset to default 4handleEnterKey
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
本文标签: javascriptFirefox onkeypress event not passing in event parameterStack Overflow
版权声明:本文标题:javascript - Firefox onkeypress event not passing in event parameter - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745576304a2157038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论