开发者

Handling keyboard shortcuts using openjs

开发者 https://www.devze.com 2023-01-07 11:46 出处:网络
I use th开发者_JAVA技巧is code http://www.openjs.com/scripts/events/keyboard_shortcuts/index.php for handling keyboard shortcuts.

I use th开发者_JAVA技巧is code http://www.openjs.com/scripts/events/keyboard_shortcuts/index.php for handling keyboard shortcuts.

  shortcut.add("Ctrl+Z",function() {
  setTimeout(function() {
    var val= $("textarea").val();
    var length = val.split("\n").length;
    alert(length);
  }, 100);
  },{
    'type':'keydown',
    'propagate':true,
    'target':document.getElementById("textarea")
 });

I have problem when ctrl+z is pressed and there is nothing to undo - the alerts 2 ,not 1.


I'm not sure what the structure of your page is (a link would be handy), but I do notice a potential issue. In one place you're requesting for an element with id "textarea":

'target':document.getElementById("textarea")

But in another place you're querying for all elements of type textarea, of which there could be multiple:

var val= $("textarea").val();

Did you intend to access an element with id "textarea" like this:

var val= $("#textarea").val();

That could be related to your issue if there are multiple textarea elements on your page.

0

精彩评论

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