jquery - Disable original javascript keypress event and replace dynamically -


Currently I have a teddyrea with an onkeypress event specified in the HTML tag, I capture this funnel and form a function I am trying to save in that it will be used to override it, because I want to add another condition to run it. Here's the code that I'm trying to implement.

  $ (document) .ready (function (e) {var default keypress = $ ('textarea') keyboard; $ ('text') .keypress (function (e) {if (FieldsChanged) {fieldsChanged = false;} else {defaultCeypress (e);}});});  

The problem I have is IE 7 & amp; 8. Both the original keyboard fire (even though the "default keypers (e);" are commented on) and the new keypress is activating. In addition to removing the onkeypress attribute from the Textarea tag (original first, then new) (I can not do this because the code is generated), is there a way to disable that basic keyboard with firing?

Thank you! Newtube

jQuery keypace Handler You pass it and do not overwrite anything No It is too much by design, in this way you can add many event handlers to the element and worry about catching any existing handlers. do not require.

You can not actually use unbind to prevent existing handlers want to stop the existing handler. You can only remove the handler anyway, however:

  var $ el = $ ('textarea'), defaultKeypress = $ el.attr ('onkeypress'); $ El.removeAttr ('onkeypress'); $ El.keypress (function (e) {if (fieldsChanged) {fieldsChanged = false;} else {return default keypress.apply (this, argument);}});  

Note that I use defaultKeypress by calling return as well as making a call with the correct scope. Code> using the result of return. This is to maintain all standard event handler environments, which the browser has called it.

Reference:


  • Comments

    Popular posts from this blog

    MySql variables and php -

    url rewriting - How to implement the returnurl like SO in PHP? -

    Which Python client library should I use for CouchdB? -