我们首先来介绍自定义选择器的开发,他的代码结构如下:
代码如下:
(function ($) {
$.expr[':'].customselector = function (object,index,properties,list) {
//code
};
})(jquery);
. 代码如下:
(function ($) {
$.expr[':'].external = function (object) {
if ($(object).is('a')) {
return object.hostname != location.hostname;
}
};
})(jquery);
. 代码如下:
(function ($) {//更新坐标位置
$.fn.updateposition = function (event) {
return this.each(function () {
$(this).css({
left: event.pagex + 20,
top: event.pagey + 5
});
});
}
//提示框插件,将显示a标签title属性的内容
$.fn.tooltip = function () {
return this.each(function () {
//获取当前对象
var self = $(this);
//获取title属性值
var title = self.attr('title');
//判断当前对象是否是a标签,title属性有无内容
if (self.is('a') && title != '') {
self.removeattr('title')
.hover(function (event) {
//鼠标在目标对象上
$('<p id="tooltip"></p>').appendto('body')
.text(title)
.hide()
.updateposition(event)
.fadein(400);
}, function () {
//鼠标移出
$('#tooltip').remove();
}).mousemove(function (event) {
//鼠标移动
$('#tooltip').updateposition(event);
});
}
});
};
})(jquery);