学习jquery基础教程的一些笔记

$.map(array,fn) 对数组array中的每一个元素调用fn函数处理,fn将处理返回。
var arr=[3,5,9];
var arr2=$.map(arr,function(item){return item*2;});

$each(array,fn)对数组每个元素进行fn处理,没有返回值。
$each(arr,function(){alert(this);});

对于数组,key为数组的序号,value为数组的值。
$("#div").html()等价于document.getElementById("div1").innerHTML();

css样式
.样式名{样式说明;}

多条件样式选择器
$("p,div,span,menuitem") 表示同时选择多个标签

节点遍历
next()获取节点之后的第一个同辈元素。
$("div").click(function(){alert($(this).next().text())});显示div内同级的下一个元素

过滤器 next("div")显示与div同级的下一个元素。

使点击节点下面所有的元素变色
$("div").click(function(){$.each($(this).nextAll("div"),function(){$(this).css("background","Red")})});
等同于
$("div").click(function(){$(this).nextAll("div").css("background","Red");});

点击变色,其他白色
$("div").click(function(){$(this).css("background","Red");$(this).siblings("div").css("background","White");});

过滤器
:first选取第一个元素,$("div:first")选取第一个div元素。
:not选取不满足条件的元素。
:even,odd;选取奇数或者偶数的元素(索引)。
:eq()   =
:gt()   >
:lt()    <
:gt(3) 在指定位置中开始算的大于3的位置
$("div[id]")选取有id属性的div

jquery中的dom操作
动态加链接var link=$("<a href='w ww.bai du.com'>百 度</a>");
                $("div:first").append(link);
append()在元素尾部添加元素。
prepend()在元素之前添加元素。

节点操作 
$("br").replaceWith("<hr/>")将br改成hr。

获取属性中的样式  attr("class")

获取已选radiobutton的值
$("input=[name=xx]:checked").val();

合成两个事件 hover(mouseover事件,mouseleave事件)

preventDefault()方法等同于window.event.returnValue=false;

hide()将元素隐藏,参数有"slow" "fast",也可以输入时间(ms)。

toggle()使元素在隐藏和可见中切换,参数与hide()相似。

posted on 2013-11-04 15:09  猫头鹰31  阅读(163)  评论(0编辑  收藏  举报