jquery使用

jquery的使用:

1. jquery注册事件:$("#btn").click(function (){ $(this).css(“backgroundColor”,“red”)})

2.jquery转换dom对象:$("bthObj").get(0)或$("btnObj")[0]

3.dom对象转jquery:$(btnObj)

4.dom获取:document.getElementById("btn")...

5.jquery获取:$("#btn")

6.js设置样式:this.style.backgroundColor="red"

7.jquery中的方法:.val()方法获取value值。.text()获取文本值。 .html()获取div中显示的元素内容。

一般的在方法中写入内容就是给元素设置内容,什么也不写是获取内容。

8.鼠标经过离开事件:$("#uu>li").mouseover(function (){ $(this).css("backgroundColor","red")})

                                   $("#uu>li").mouseout(function (){ $(this).css("backgroundColor","")})

9.获取所有的子元素children:$(this).children("ul").show();

10.索引选择器:eq(3)判断索引与3相等的。 lt(3)判断索引小于3的。 gt(3)判断索引大于3的。

11.获取当前的索引值:var index=$(this).index

   以下一般处理tab栏切换问题一类的如下:

    判断相等的:$("#center>li:eq('+index+')").siblings("li").hide();

                         $("#center>li:eq('+index+')").show();

12. .find()方法针对当前元素找里面的一些其他元素。

 处理下拉菜单显示隐藏问题:

       $(this).children("ul").find("li").show();

       $(this).siblings("li").find("ul").find("li").hide();

猜你喜欢

转载自www.cnblogs.com/duanzhange/p/8926198.html