开发者

switching default keyevents actions after key combinations

开发者 https://www.devze.com 2022-12-28 02:53 出处:网络
I need to change default actions of two events. When I press \"enter\" one action occurs, when I press \"shift-enter\" another. I need to switch it. I means if I press \"enter\" than \"shift-enter\"

I need to change default actions of two events.

When I press "enter" one action occurs, when I press "shift-enter" another. I need to switch it. I means if I press "enter" than "shift-enter" action occurs. I tried something like this but if doesn't work.

  f(evt.keyCode == 13) {
    if(!evt.shiftKey){开发者_C百科
      evt.preventDefault();
      evt.shiftKey = true;
      var e = jQuery.Event("keydown");
      e.which = 13;
      e.shiftKey = true;
      $(wym._doc).trigger(e);

Is there any way to do it?


Here try this :

$(function() {
    $('#myinput').keypress(function(e) {
        if(e.shiftKey && e.which == 13) {
            alert('shift enter');
        } else if(e.which == 13) {
            alert('enter');
        }
    });
});
0

精彩评论

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