下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
data()函数
$("#btn1").click(function(){ $("div").data("greeting","Hello World"); }); $("#btn2").click(function(){ alert($("div").data("greeting")); });
$("#btn2").click(function(){ $("div").removeData("greeting"); alert("Greeting is: " +$("div").data("greeting")); });
map()函数
$("p").append($("input").map(function(){ return $(this).val(); }).get().join(",") ); result: <p>John,password,http://ejohn.org/</p> $.map(attr,function(ele,index){ if(ele>5&&index<8){ return ele+1; } //将数组中元素值大于5并且序号小于8的元素加1 });
$.param()函数
var myObject = { a: { one: 1,two: 2,three: 3 },b: [1,2,3] }; var recursiveEncoded = $.param(myObject); var recursiveDecoded= decodeURIComponent($.param(myObject)); alert(recursiveEncoded); alert(recursiveDecoded);
recursiveEncoded和 recursiveDecoded 的值输出如下:
$.proxy()函数
var objMyInfo = { name : "clf",sex : "男",ShowEvent : function(){ alert(this.name+"****"+this.sex); } } $("#bnt").bind("click",$.proxy(objMyInfo.ShowEvent,objMyInfo));
如果不用proxy函数,则出发click 事件时,调用objMyInfo.ShowEvent函数,此函数内的this关键字将指向非objMyInfo上下文,那么,this.name和this.sex都将是一个undifined的变量
$.trim(“ text ”)
$.support
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。