1

I am using openjs.com's shortcut handling (1) to disable the enter key in my html forms. However, inside of textareas in those forms I want enter key to emit the normal CR-LF pair (because that's what users expect).

At the moment assuming I have a form/input structure as follows:

<form id="f1">
 <fieldset>
  <input>
  <textarea id="f2"> ...

The following scripts are run:

shortcut.add('Return',  function () { /*empty*/   },
 { 'type':'keydown', 'disable_in_input':false,'propagate':true,  
   'target':document.getElementById('f1')});"

This effectively disables the enter key.

I have tried using the following code to re-enable it for the textarea:

shortcut.add(\"Enter\", function() { }, {'type':'keydown','propagate':false,
'disable_in_input':false, 'target':document.getElementById('f2') } );  

But that does not work. What is the order of propagation of this event? Should it bubble up from the textarea or bubble down from the form element?

4

1 回答 1

3

看起来这个库并不是真的要以这种方式使用。我会冒险猜测添加任何快捷方式都会完全禁用浏览器对其的处理,无论您之后做什么。

你实际上想要完成什么?如果你只是想阻止表单被提交,你可以为调用的整个表单添加一个submit 事件监听event.preventDefault()器。

于 2009-08-23T21:33:34.310 回答