设为首页 加入收藏

TOP

jQuery中添加自定义或函数方法
2014-11-24 13:59:54 来源: 作者: 【 】 浏览:0
Tags:jQuery 添加 定义 函数 方法

方法一:
jQuery.fn.setApDiv=function () {
//apDiv浮动层显示位置居中控制
var wheight=$(window).height();
var wwidth=$(window).width();
var apHeight=wheight-$("#apDiv").height();
var apWidth=wwidth-$("#apDiv").width();
$("#apDiv").css("top",apHeight/2);
$("#apDiv").css("left",apWidth/2);
}


调用方法:$("#apDiv").setApDiv();



--------------------------------------------------------------------------------
方法二:
//jQuery 应用扩展
jQuery.extend({
// 设置 apDiv
setApDiv:function () {
//apDiv浮动层显示位置居中控制
var wheight=$(window).height();
var wwidth=$(window).width();
var apHeight=wheight-$("#apDiv").height();
var apWidth=wwidth-$("#apDiv").width();
$("#apDiv").css("top",apHeight/2);
$("#apDiv").css("left",apWidth/2);
}
});
调用方法:$.setApDiv();


总结一种如$.extend({'aa':function(){}}),这种调用时就是这样$.aa(),另一种如$.fn.extend({'aa':function(){}}),这种调用时就得这样,$(this).aa()
--------------------------------------------------------------------------------
方法三:

$.postJSON = function(url, data, callback) {
$.post(url, data, callback, "json");
};
调用方法:$.postJSON('/post/getsecurejsonpost',{}, function(data) {});


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇jQuery操作DOM 下一篇Android Activity 和 HTML 数据通..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: