开发者

jQuery 'event not defined' error on simulated key press

I am currently trying to use jQuery to enter a selection from a dropdown into a text box, simulate a click to select it, press return, wait for some proc开发者_开发技巧essing and then press return again. It's quite a nasty way of getting what I need but it's the only way I can see at the moment. Here is the code:

$('#fav').change(function() 
{
  $('#contract_input').val($('#fav').val());
  $('#contract_input').trigger('click');
  e = jQuery.Event("keypress");
  e.which = 13;
  $('#contract_input').trigger(e).delay(500).trigger(e);
}

The issue I am having is that IE8 is giving an error on the page:

'Event' is not defined

The click seems to work, it's just the return that does not.

Any ideas?


Consider using keydown instead of keypress and in IE you could try setting e.keyCode instead of e.which.

e.g.

e = jQuery.Event("keydown");
e.keyCode = 13;
$('#contract_input').trigger(e).delay(500).trigger(e);


Edit again: $('#contract_input').keypress(function (e) { do Stuff }); Should be used instead http://api.jquery.com/keypress/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜