Jqurey学习(1)

第一个Jqurey例子
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button type="button">Click me</button> <button type="button">Click me1</button> </body> </html>

代码解读:

$:美元符号,是一个选择符(Selector)用来“查找”和“查询”HTML元素的;

$(document):取得了整个页面的对象

$(document).ready:相当于.net 后台代码的:pageonload事件,$(document).ready()的参数是一个函数,页面一开始就加载了相关的方法。

$("button"):取到该页面的所有type为:button的html元素,$("button").click,给所有的button添加click事件,其实click方法里的参数也是一个函数,

其函数体的内容是:$("p").hide()所有的"p"元素都被隐藏。

原文地址:https://www.cnblogs.com/fanxiaojun/p/2672569.html