I have an email form submitter and i want to make it onEnter submittable (not just click)
开发者_Python百科Here is my code for the button
submitBtn.addEventListener(MouseEvent.CLICK, submitForm);
function submitForm(e:Event) {
///do stuff
}
Here is the code for the text field
emailAddress.addEventListener(KeyboardEvent.KEY_DOWN,handler);
function handler(event:KeyboardEvent){
if(event.charCode == 13){
//submitForm() < this doesn't work (Expected 1)
}
}
Thanks
emailAddress.addEventListener(KeyboardEvent.KEY_DOWN,handler);
function handler(event:KeyboardEvent)
{
if(event.charCode == 13)
{
submitForm(null)
}
}
submitBtn.addEventListener(MouseEvent.CLICK, submitForm);
emailAddress.addEventListener(KeyboardEvent.KEY_DOWN, handler);
function submitForm(e:MouseEvent=null)
{
///do stuff
};
function handler(event:KeyboardEvent)
{
if(event.charCode == 13) submitForm();
};
The function submitForm(); expects 1 parameter to be passed which is an event type variable:
function submitForm(e:Event)
Therefore you need to set a default value in case the parameter is not passed:
function submitForm(e:MouseEvent=null)
精彩评论