2014.12.25 jQuery学习笔记

jQuery 事件函数

jQuery 事件处理方法是 jQuery 中的核心函数。

事件处理程序指的是当 HTML 中发生某些事件时所调用的方法。术语由事件“触发”(或“激发”)经常会被使用。

通常会把 jQuery 代码放到 <head>部分的事件处理方法中:

 

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p#hello").hide();
});
});
</script>
</head>

<body>
<h2>This is a heading</h2>
<p id="hello">This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
</html> 

  jQuery attr() 方法用于获取属性值。

 

jQuery after() 和 before() 方法

jQuery after() 方法在被选元素之后插入内容。

jQuery before() 方法在被选元素之前插入内容。

 

find() 方法返回被选元素的后代元素,一路向下直到最后一个后代。

 

siblings() 方法返回被选元素的所有同胞元素。

 

first() 方法返回被选元素的首个元素。

下面的例子选取首个 <div> 元素内部的第一个 <p> 元素:

 

 

eq() 方法返回被选元素中带有指定索引号的元素。

索引号从 0 开始,因此首个元素的索引号是 0 而不是 1。下面的例子选取第二个 <p> 元素(索引号 1):

实例

$(document).ready(function(){
  $("p").eq(1);
});


not() 方法返回不匹配标准的所有元素。

提示:not() 方法与 filter() 相反。

posted on 2014-12-25 15:39  阿追#可视化  阅读(108)  评论(0编辑  收藏  举报

导航