Sunday 15 February 2015

javascript - adding click event to body when input is focussed on, then removing it on blur -


I have a text input that I want, when the focus is on, anywhere on the one click event register Do body . But when removed from focus, that click event is removed from the body Regrettably, I think I am not able to do it.

  $ (document) .ready (function () {$ ("html"). ("Focus", "#sdf" ("Blue", "# ASDF"), $ ( $ ("HTML"), $ ("body"). ("Click", "*: not (# SADF)", was ITClicked;}); $ ("html"), function () {$ (" ("Yes");}   

("click", "*", was ITClicked);});}); The function was ItClicked ()

Thanks for any help.

When #ddsf gets focused , And some other element is clicked, then click the mouse, blur, mouseup, in the event fire. The handler has been removed before clicking.

The Masudown event sets a fire before the blurring. If you are OK with the mouse instead of the click, you can use it:

  $ (document) .ready (function () {$ ("# asdf"). On ("focus", ("blur", function () {$ ("body"). "Mousedown", was ITClicked;}); $ ("# asdf"). "Musudown", was ITClicked;});});   

Edit:

To help determine whether you are losing focus due to a click You can use the MusDown event, and you can remove the handler if the focus is lost in the click handler.

  $ (document) .ready (function () {$ ("# asdf"). ("Focus", function () {$ (but "blurred", functions () " $ "(" Mosque ", setdown); $ (" body "). (" Click ", was ITClicked);}); $ (" # asdf "). $ (" $ ") ($ (This) $ ("Mousedown", setdown); $ ("body") off ("click" WasItClicked);}}}; ); Function setdown () {$ ("# asdf") et ("mouse", "down");} function wasItClicked () {if ($ ("# asdf") = $ (document.activeElement)) $ $ ("Mouse", "set"); $ ("mouse"); $ ("mouse"); ("click" was, ITClicked);} $ ("#sdf") atr ("mouse", "up" ); Alert ("Yes");}   



No comments:

Post a Comment