这个是我自己写的获取点击按钮的坐标,并将相应的div显示,绝对定位//弹出层
function PopDiv(inputId, divID) {
var positiontop = $("#" + inputId + "").position().top;
var positionleft = $("#" + inputId + "").position().left;
var elementWidth = $("#" + inputId + "").width();
var elementHeight = $("#" + inputId + "").height();
$("#" + divID + "").css({ position: "absolute", 'top': positiontop + elementHeight, 'left': positionleft + elementWidth, 'z-index': 2 });
$("#" + divID + "").show();
}但是导入另个一插件之后,就总是调用那里面的方法。结果不是显示我的div而是显示那个类库里面的div(function ($) {
//绝对定位定位
$.getPostion = function (obj) {
var actualTop = obj.offsetTop;
var actualLeft = obj.offsetLeft;
var current = obj.offsetParent;
while (current !== null) {
actualTop += current.offsetTop;
actualLeft += current.offsetLeft;
current = current.offsetParent;
}
return { left: actualLeft, right: actualLeft + obj.offsetWidth, top: actualTop, bottom: actualTop + obj.offsetHeight };
};
} (jQuery));(function($) {
$.extend($.fn, {
position: function(options) {
if (!options) {
options = {};
options.suggesttype = "startPort_suggest";
options.sourcetype = "port_source";
}
var p = new $.positionor(options, this);
}
});
$.positionor = function(options, inputs, lists) {
this.currentInput = null;
this.render = '<div class=\"portlist\" id=\"Postion\" style=\"position:absolute;z-index:120;overflow:hidden;display:none;\">' +
'<div class=\"port_warpperjzx\">' +
'<div class=\"port_msg\" id=\"port_message\"> <\/div>' +
'<div class=\"port_contxt\" id=\"port_list\">' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span><\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span><\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<\/div>' +
'<\/div>' +
'<\/div>';
if ($("#Postion").length == 0) {
$(this.render).prependTo('body');
}
$.fullSearch(this.currentInput, options);
inputs.each(function(i, e) {
var $e = $(e);
if (i == 0)
this.currentInput = e;
this.currentItem = -1;
$e.focus(function(event) {
var p = $.getPostion(event.target);
$("#Postion").css({ top: p.bottom, left: p.left });
$("#Postion").fadeIn('slow');
$("#Postion").show();
this.currentInput = event.target;
});
$e.blur(function(event) {
if ($("#Postion").css("display") != "none") {
$("#Postion").hide();
if (event.target.value != "") {
var v = $("#port_list> a:first >span").text(); //.replace(/@/g, "").split("|");
event.target.value = v; //v[3].trim();
}
}
this.currentInput = null;
});
$e.change(function(event) { });
$e.keyup(function(event) {
$.fullSearch(this.currentInput, options, event.target.value);
});
$e.click(function(event) {
var p = $.getPostion(event.target);
$("#Postion").css({ top: p.bottom, left: p.left });
$("#Postion").show();
$.fullSearch(this.currentInput, options, event.target.value);
})
});
};
$.sortSearch = function(a, b) {
var c = a.match(/^[^\|]+/), d = b.match(/^[^\|]+/);
return c > d ? 1 : (c.length == d.length ? 0 : -1);
};
$.fullSearch = function(input, options, value) {
var $Suggest = $.positionor.defaults[options.suggesttype];
var $Source = $.positionor.defaults[options.sourcetype];
if (value)
value = value.replace(/\(/gi, "\\(").replace(/\)/gi, "\\)");
if (value) {
$('#port_message').text("查找:" + value.replace(/\\/gi, ""));
var rgSource = new RegExp("@[^@]*" + value + "[^@]*", "gi");
data = $Source.match(rgSource);
data.sort($.sortSearch); }
else {
var rgSuggest = new RegExp("[^@]+@", "gi");
$('#port_message').text("默认列表");
data = $Suggest.match(rgSuggest);
}
if (data) {
$("#port_list a").each(function(i, e) {
var $e = $(e);
if (data[i]) {
var item = data[i].replace(/@/g, "").split("|");
if (i == 0)
$(input).attr("vid", item[2]);
$e.html("<span>" + (item[3] || item[0]) + "</span>" + item[1]);
$e.unbind("mousedown");
$e.bind("mousedown", function(event) {
if (input) {
$input = $(input);
$input.val(item[3] || item[0]);
$input.attr("vid", item[2]);
$AppendValue = $("#" + $input.attr("appendvalue"));
if ($AppendValue.length > 0)
$AppendValue.val(item[1]);
$input.attr("vCountry", item[1]);
$("#Postion").hide();
} });
}
else {
$e.unbind("mousedown");
$e.empty();
$e.addClass("anone");
}
});
}
else {
$('#port_message').text("对不起, 找不到: " + value);
}
}
function PopDiv(inputId, divID) {
var positiontop = $("#" + inputId + "").position().top;
var positionleft = $("#" + inputId + "").position().left;
var elementWidth = $("#" + inputId + "").width();
var elementHeight = $("#" + inputId + "").height();
$("#" + divID + "").css({ position: "absolute", 'top': positiontop + elementHeight, 'left': positionleft + elementWidth, 'z-index': 2 });
$("#" + divID + "").show();
}但是导入另个一插件之后,就总是调用那里面的方法。结果不是显示我的div而是显示那个类库里面的div(function ($) {
//绝对定位定位
$.getPostion = function (obj) {
var actualTop = obj.offsetTop;
var actualLeft = obj.offsetLeft;
var current = obj.offsetParent;
while (current !== null) {
actualTop += current.offsetTop;
actualLeft += current.offsetLeft;
current = current.offsetParent;
}
return { left: actualLeft, right: actualLeft + obj.offsetWidth, top: actualTop, bottom: actualTop + obj.offsetHeight };
};
} (jQuery));(function($) {
$.extend($.fn, {
position: function(options) {
if (!options) {
options = {};
options.suggesttype = "startPort_suggest";
options.sourcetype = "port_source";
}
var p = new $.positionor(options, this);
}
});
$.positionor = function(options, inputs, lists) {
this.currentInput = null;
this.render = '<div class=\"portlist\" id=\"Postion\" style=\"position:absolute;z-index:120;overflow:hidden;display:none;\">' +
'<div class=\"port_warpperjzx\">' +
'<div class=\"port_msg\" id=\"port_message\"> <\/div>' +
'<div class=\"port_contxt\" id=\"port_list\">' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span><\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span><\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<a class=\"a1\" href=\"javascript:;\"><span> <\/span> <\/a>' +
'<\/div>' +
'<\/div>' +
'<\/div>';
if ($("#Postion").length == 0) {
$(this.render).prependTo('body');
}
$.fullSearch(this.currentInput, options);
inputs.each(function(i, e) {
var $e = $(e);
if (i == 0)
this.currentInput = e;
this.currentItem = -1;
$e.focus(function(event) {
var p = $.getPostion(event.target);
$("#Postion").css({ top: p.bottom, left: p.left });
$("#Postion").fadeIn('slow');
$("#Postion").show();
this.currentInput = event.target;
});
$e.blur(function(event) {
if ($("#Postion").css("display") != "none") {
$("#Postion").hide();
if (event.target.value != "") {
var v = $("#port_list> a:first >span").text(); //.replace(/@/g, "").split("|");
event.target.value = v; //v[3].trim();
}
}
this.currentInput = null;
});
$e.change(function(event) { });
$e.keyup(function(event) {
$.fullSearch(this.currentInput, options, event.target.value);
});
$e.click(function(event) {
var p = $.getPostion(event.target);
$("#Postion").css({ top: p.bottom, left: p.left });
$("#Postion").show();
$.fullSearch(this.currentInput, options, event.target.value);
})
});
};
$.sortSearch = function(a, b) {
var c = a.match(/^[^\|]+/), d = b.match(/^[^\|]+/);
return c > d ? 1 : (c.length == d.length ? 0 : -1);
};
$.fullSearch = function(input, options, value) {
var $Suggest = $.positionor.defaults[options.suggesttype];
var $Source = $.positionor.defaults[options.sourcetype];
if (value)
value = value.replace(/\(/gi, "\\(").replace(/\)/gi, "\\)");
if (value) {
$('#port_message').text("查找:" + value.replace(/\\/gi, ""));
var rgSource = new RegExp("@[^@]*" + value + "[^@]*", "gi");
data = $Source.match(rgSource);
data.sort($.sortSearch); }
else {
var rgSuggest = new RegExp("[^@]+@", "gi");
$('#port_message').text("默认列表");
data = $Suggest.match(rgSuggest);
}
if (data) {
$("#port_list a").each(function(i, e) {
var $e = $(e);
if (data[i]) {
var item = data[i].replace(/@/g, "").split("|");
if (i == 0)
$(input).attr("vid", item[2]);
$e.html("<span>" + (item[3] || item[0]) + "</span>" + item[1]);
$e.unbind("mousedown");
$e.bind("mousedown", function(event) {
if (input) {
$input = $(input);
$input.val(item[3] || item[0]);
$input.attr("vid", item[2]);
$AppendValue = $("#" + $input.attr("appendvalue"));
if ($AppendValue.length > 0)
$AppendValue.val(item[1]);
$input.attr("vCountry", item[1]);
$("#Postion").hide();
} });
}
else {
$e.unbind("mousedown");
$e.empty();
$e.addClass("anone");
}
});
}
else {
$('#port_message').text("对不起, 找不到: " + value);
}
}
js中还能使用命名空间吗?