jquery

为标签id=id1及其之后的所有标签加上背景色:

方法1:$("#id1").nextAll().css("background-color","red").end().css("background-color","red");

方法2:$("#id1").nextAll().andSelf().css("background-color","red");//推荐这个

注意:end(),andSelf()的作用

$("#id1").nextAll().andSelf().end().end()css("background-color","red");//仅id=id1的元素变色

end()返回上一次包装集被破坏之前的状态,即回到最近的一个"破坏性"操作之前

andSelf()并且加入自己

$("#tb1 tr:not(:first):lt(3)").css({"font-size":"16px","text-align":"center"});//把id为tb1的表格的前三行设置css。不包括第一行

$("#tb1 tr:not(:first):not(:last):odd")//不包含首尾的奇数行

//相对定位

$("#tb tr").click=function(){

$("td");//当前tb表格的所有行的所有td

$("td",$(this)).css("background-color","red");//当前行的所有td。$(,)如果有两个参数的时候,是指在$(this)里面来查找td,否则是找全部的td

$("td",$(this)).eq(1).css("background-color","red");//当前行的第二个td

}

$(function(){

  $("input").focus(function(){

    $(this).addClass("class1");

)}.blur(function(){

$(this).removeClass("class1");

})

})

$(":input")与$("input")区别:

$(":input")选区所有input  select textarea button元素。

$("input")只获得input元素。

$(":text")选取单行文本框,等价于$("input[type=text]")

$(":password")获取密码框

jquery获取radio单选框的值与checkbox多选框的值;

多选框的值要遍历;

radio单选框:

$("input[name=sex]:checked").val()

checkbox多选框:

$("input[type=checkbox]:checked").each(function(){

  var v=$(this).val();

})

在each()中return false就相当于break,return true就相当于continue

原文地址:https://www.cnblogs.com/lxboy2009/p/4134903.html