开发者

"Bind" [Key Press] with [Click]

开发者 https://www.devze.com 2023-02-18 11:00 出处:网络
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

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)

0

精彩评论

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