Diferencia entre revisiones de «Usuario:Juanda/jQuery/Eventos»
De WikiEducator
(→Ejemplo) |
|||
Línea 142: | Línea 142: | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html> | <html> | ||
− | <head> | + | <head> |
<style> | <style> | ||
− | button { margin:5px; } | + | button { margin:5px; } |
− | button#theone { color:red; background:yellow; } | + | button#theone { color:red; background:yellow; } |
− | </style> | + | </style> |
<script src="http://code.jquery.com/jquery-latest.js"></script> | <script src="http://code.jquery.com/jquery-latest.js"></script> | ||
− | </head> | + | </head> |
− | <body> | + | <body> |
− | + | <button id="theone">Does nothing...</button> | |
− | <button id="bind">Add Click</button> | + | <button id="bind">Add Click</button> |
− | <button id="unbind">Remove Click</button> | + | <button id="unbind">Remove Click</button> |
− | <div style="display:none;">Click!</div> | + | <div style="display:none;">Click!</div> |
− | <script> | + | <script> |
− | function aClick() { | + | function aClick() { |
− | + | $("div").show().fadeOut("slow"); | |
− | } | + | } |
− | $("#bind").click(function () { | + | $("#bind").click(function () { |
− | + | $("body").on("click", "#theone", aClick) | |
− | + | .find("#theone").text("Can Click!"); | |
− | }); | + | }); |
− | $("#unbind").click(function () { | + | $("#unbind").click(function () { |
− | + | $("body").off("click", "#theone", aClick) | |
− | + | .find("#theone").text("Does nothing..."); | |
− | }); | + | }); |
− | </script> | + | </script> |
− | + | </body> | |
− | </body> | + | |
</html> | </html> | ||
</source> | </source> | ||
</div> | </div> | ||
</div> | </div> |
Revisión de 08:11 12 nov 2012