开发者

Sending/printing a key with jQuery.Trigger

开发者 https://www.devze.com 2022-12-28 22:29 出处:网络
i think i have read every page google knows about which has these keywords, and nothing works for me.

i think i have read every page google knows about which has these keywords, and nothing works for me.

what i have is a form input, and a button next to it [not submit], and what i want is for the button click to trigger an 'enter' key click. [this will respectively run another function which is already working..]

i've tried

<input id='inputBtn' type='button' .... onclick='$('#otherInput').trigger('keypress',[13]);' >

and also putting it in a function and then running it from onclick, or making a

$('#inputBtn').click(function().....

nothing works for me ple开发者_开发百科ase help!!


$('input').trigger({
  type:  'keypress',
  which:  13
});

--EDIT--

you might want to extend that with

keyCode: 13,
charCode: 13

etc.


You might need to provide some example code. I can't think of any reason you couldn't just have the second function (that runs when enter is pressed) being called by the click event on your button.

function onEnter()
{
 //Do something
}

jQuery("#inputButton").live("click",onEnter());

Should work.

0

精彩评论

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