Jquery常用的选择器有哪些?
1、基本选择器:#id 、element 、.class 、* 、selector1,selector2,selectorN
2、层次选择器:ancestor descendant 、parent > child 、prev + next 、prev ~ siblings
3、基本过滤器选择器:first 、:last 、:not 、:even 、:odd 、:eq 、:gt 、:lt 、:header 、:animated
4、内容过滤器选择器:contains 、:empty 、:has 、:parent
5、可见性过滤器选择器:hidden 、:visible
6、属性过滤器选择器[attribute] 、[attribute=value] 、[attribute!=value] 、[attribute^=value] 、[attribute$=value] 、[attribute*=value] 、[attrSel1][attrSel2][attrSelN]
7、子元素过滤器选择器:nth-child 、:first-child 、:last-child 、:only-child
8、表单选择器:input 、:text 、:password 、:radio 、:checkbox 、:submit 、:image 、:reset 、:button、:file 、:hidden9、表单过滤器选择器:enabled 、:disabled 、:checked 、:selected
JQUERY如何获得某元素父级的父级?
parent()是 父元素 就一个,你要选取class=x的元素,就是第一个p元素的父元素的父元素:$("p:eq(0)").parent().parent().css("background", "yellow");或者p元素父元素的父元素类为x的元素:$("p").parent().parent(".x").css("background", "yellow");或者p元素祖先元素(祖先就很多个了)中类为x的元素: $("p").parents(".x").css("background", "yellow");
jquery如何给dom添加单击事件?
直接使用click事件是不起作用的,我平常使用的两种方法 1、on事件 var html1=''; html1 +=`
确认提交 暂不提交
` $('.modal-footer').append(html1); $('div').on('click','.sure',function(){console.log("+++");}); 2、onclick事件 var html1=''; html1 +=`确认提交 暂不提交
` $('.modal-footer').append(html1); functionsure(){console.logO("===");} 需要获取到div这个元素,可以通过id,class等等方式得到,比如说div的id为"div1",那么就可以这么写了。$('#div1').click(function(){//这里面就是click事件的内容了});