美文网首页
jquery常用的选择器

jquery常用的选择器

作者: 沉思的老猫 | 来源:发表于2017-11-27 15:46 被阅读0次

1、结构

$('选择器')

$('选择器 上下文')

2、选择器

1)元素选择器

$('#demo'):选取所有 id="demo" 的元素

$('a'):选择所有a元素

$(this): 当前 HTML 元素

2)属性选择器

$("[href]") :选取所有带有 href 属性的 元素

$("[href='#']") :选取所有带有 href 值等于 "#" 的 元素

$("[href!='#']") :选取所有带有 href 值不等于 "#" 的 元素

$("[href$='.jpg']"): 选取所有 href 值以 ".jpg" 结尾的 元素

$('li:first').css('background','red')

$('input[type="text"]'):表单type=text的 元素

$('input:text'):表单type=text的 元素

$(':text'):表单type=text的 元素

$(':radio'):表单type=radio的 元素

$(':checkbox'):表单type=checkbox的 元素

$(':file'):表单type=file的 元素

$(":enabled"):所有激活的 input 元素

$(":disabled"):所有禁用的 input 元素

$(":selected"):所有被选取的 input 元素

$(":checked"):所有被选中的 input 元素

$('input[name^=playerType-]'):选出name包含playerType-]的元素

$('div[id^=history-]'):选出id包含history-的元素

$(this).parent().find('a'):父元素下所有a的元素

$('p :parent'):父元素

$('td:contains(" 女 ")'):选出内容是女的元素

$('li:first'):首个元素

$('li:eq(2)'):第3个 元素

$('li:gt(2)'):大于3的所有元素

$('li:lt(2)'):小于3所有元素

$("p:last"):最后一个元素

$('li:odd'):奇数元素

$("tr:even"):偶数元素

3)CSS 选择器

$('div'):选择所有div元素

$('p') :选择所有p元素

$('.demo'):选取所有 class="demo" 的元素

3、赋值

$(this).attr('属性名','动态值') :针对所有

$(this).val('动态值'):input :text赋值

$('input[name="type"][value="值"]').attr("checked",true):radio、checkbox赋值选中

4、下拉框change事件

$('body').on('change','select[name="xxx"]',function() {console.log($(this).val());}});

5、动态页面绘画

html模板

动态页面在页面绘画模板,js数据填充,用replace替换

{{}} -> 动态值 ,适用单个替换  templet.replace('{{name}}',newName);

#id -> 动态值 ,适用多个替换,用正则 templet.replace(/#id/g,newName);

var tableTemplet=$('#app-type-templet').html();

var tbodyTemplet=$('#app-type-templettbody').html();

var checkBoxTemplet=$('#app-type-templettbody#td-templet').html();

var html=tableTemplet.replace(tbodyTemplet,'{{tbody}}');

var tbody , tbodyHtml=tbodyTemplet.replace(checkBoxTemplet,'{{app}}');

var serie = tbodyHtml.replace('{{appType}}',serie.name).replace('{{app}}','内容');

$('#app-types').append(html.replace('{{tbody}}',tbody));

相关文章

  • jQuery选择器

    一、jQuery常用选择器 二、jQuery选择器优势 三、jQuery常用基本选择器 四、jQuery常用层次选...

  • 【小结】jQuery选择器

    jQuery选择器是jQuery中最常用的,是jQuery的核心大致有以下几种选择器: 基本选择器 多项选择器 层...

  • jQuery选择器总结

    jQuery选择器完全继承了css的风格 常用的css选择器 jQuery选择器获取的是jQuery对象,即使获取...

  • jQuery中选择器有哪几种

    jQuery选择器 一、基本选择器 基本选择器是jQuery中最常用也是最简单的选择器,它通过元素的id、clas...

  • jQuery选择器总结

    参考 jQuery选择器总结 jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#...

  • jQuery的常用选择器

    JQuery一些常用选择器的属性和方法

  • jQuery DOM教辅

    jQuery 常用的函数 一、jQuery DOM 元素方法 .get() 获得由选择器指定的 DOM 元素。 ....

  • jquery选择器书目录

    jquery选择器-基本选择器 jquery选择器-层级选择器 jquery选择器-基本过滤选择器 jquery选...

  • JQUERY一

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器 jQuery 事件 jQuery...

  • jQuser有选择器

    jQuery基本选择器 jQuery过滤选择器 jQuery层级选择器 jQuery筛选选择器(方法)

网友评论

      本文标题:jquery常用的选择器

      本文链接:https://www.haomeiwen.com/subject/jznzvxtx.html