Jquery注册事件实现方法

本文实例讲述了Jquery注册事件实现方法。分享给大家供大家参考。具体如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>事件绑定</title> <script src="https://www.jb51.net/jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript"> var oldColor; $(function () { //注册ID为btnTest的按钮的click事件 $("#btnTest").click(function () { var $divs = $("div"); $divs.html("我是修改后的Div文本"); }); //注册ID为btnTest的按钮的mouseover事件,鼠标经过时添加背景色 $("#btnTest").mouseover(function () { oldColor = $("#btnTest").css("background-color"); $("#btnTest").css("background-color", "green"); }); //注册ID为btnTest的按钮的mouseout事件,鼠标离开时还原背景色 $("#btnTest").mouseout(function () { $("#btnTest").css("background-color", oldColor); }); }); </script> </head> <body> <div> <div>我是div1 <div>我是孙子div <div>我是孙子的孙子div</div> </div> <div>我是孙子div</div> </div> <div>我是div2</div> </div> <div></div> <div></div> <input type="button" value="测试按钮" /> <div></div> </body> </html>

希望本文所述对大家的jQuery程序设计有所帮助。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgjwyz.html