过滤器、文档操作

内部处理

$('.container').append('456');

  $('.container').prepend('456');#在前面加

不刷新时在后面加内容或前面加内容

<input type='button' id='add' value='add'/>

<div  class='container'>123</div>

<script>

$(#add).click(function(){

  $('.container').append('456');

  $('.container').prepend('456');#在前面加

})

</script>

替换

replaceWith(content|fn)

repalceAll(selector)

删除

empty()

remove(【expr】)

detach([expr])

筛选器

过滤

等于eq

$('tr:eq(1)') ==$('tr').eq(1)

hasclass 有没有这个class

<div class='container'>

 <div>

  <div class='title'>Menu1</div>

  <div class='body'>

    <div class='body'>

    <a href=''>content1</a>

    <a href=''>content2</a>

   </div>

  </dvi>

  

<div>

  <div class='title'>Menu2</div>

  <div class='body'>

    <div class='body hide'>

    <a href=''>content1</a>

    <a href=''>content2</a>

   </div>

  </dvi>

</div>

</div>

<script>

 $(function(){

  $('.title').click(function(){

  $(this).parent().siblings().children('.body').addClass('hide');

  $(this).next().removeClass('hide');#仅挨着我的兄弟增加属性

});

})

</script>

事件

文档树加载完成

$(document).ready(function(){

});

或$(function($){

//你可以在这里继续使用$作为别名

});

blur([[data],fn]) 获得焦点和失去焦点

bind(type,[data],fn)一次性绑定多个事件

$(‘#foo’).bind('mouseenter mouseleave',function(){

$(this).toggleClass('entered');

});

自定义事件

<label>

<table id='body'>

<tr><td><input name='nid' type=checkbox'/></td><td></td>

</tr>

</table>

 

<script type='text/javascript'>

$(function(){

  $('.title').click(function(){

    $(this).parent().siblings().children('.body').addClass('hide');

    $(this).next().removeClass('hide');

  }).dbclick()

});

$(function(){

  $('#all').click(function(){

  $('#body').allcheck();

});

});

(function(){

  //$('#body').allcheck();

  jQuery.fn.extend({

    allcheck:function(){

      $(this).find(':checkbox').each(function(){

        this.checked=true;

      })

    },

});

//$.allcheck('#body')

jQuery.extend({

  jallcheck:function(arg){

    $(arg).find(':checkbox').attr('checked',false)

  }

  })

})();

</script>

 

posted @ 2019-03-24 16:42  期待me  阅读(72)  评论(0)    收藏  举报