jQuery工具函数

来源:互联网 发布:linux 查看文件 命令 编辑:程序博客网 时间:2024/05/17 07:57
<!doctype html><html><head><meta charset="utf-8"><title>工具函数</title><script src="../websites/jquery-3.1.0.min.js"></script></head><body><div id="show" style="width:100px; height:100px; background:red">  <p id="ow"></p></div></body></html><script>$(function(){//遍历数组、对象var arr = ['鸣人','佐助','小樱','卡卡西','伊鲁卡'];        $.each(arr,function(index,value){$('#show').html($('#show').html()+(index+1)+'.'+value+'<br>');})*//遍历对象$.each($.ajax(),function(name,fn){$('#show').html($('#show').html()+name+fn+'<br>');})//数据筛选var arr = [2,4,6,8,9,10,15,18];var arrGrep = $.grep(arr,function(element,index){return index<5&&element>8;})    alert(arrGrep);//数据修改var arrMap = $.map(arr,function(element,index){//return element;//返回所有数据if(index<5 && element >8){return element+1;//修改数据}})alert(arrMap);//查找数据的索引(可用来判断数据是否在一个数组内)alert($.inArray(11,arr));//如果存在,返回该数据在数组中的索引//合并数组var arr1 = [200,300];var new_arr = $.merge(arr,arr1);alert(new_arr);
        //数组去重
        $.unique();
//判断一个节点是否被另一个节点包含alert($.contains($('#show').get(0),$('#ow').get(0)));//判断数据类型alert($.type(arr));//判断是否为数字var num = 1;alert($.isNumeric(num));//URL操作var obj = {name:'Lee',age:100}alert($.param(obj));//转化成URL的字符串//调整this指向问题var obj = {name :'Lee',test :function(){alert (this);alert (this.name);}}//obj.test();$('#show').click($.proxy(obj,'test'));})</script>

0 0
原创粉丝点击