SoFunction
Updated on 2025-03-01

Email drop-down automatic filling selection sample code attached


(function($){
$. = function(options){
var defaults = {
boxClass: "mailListBox", //External box style
listClass: "mailListDefault", //Default list style
focusClass: "mailListFocus", //Select the style in the list
markCalss: "mailListHlignt", // Highlight style
zIndex: 1,
autoClass: true, //Whether to use the plug-in with its own class style
mailArr: ["","","","","","","","","","","","","",""], //Email Array
textHint: false, // Automatic display and hide of text prompts
hintText: "",
focusColor: "#333",
blurColor: "#999"
};
var settings = $.extend({}, defaults, options || {});

//Page loading CSS style
if( && $("#mailListAppendCss").size() === 0){
$('<style type="text/css">.mailListBox{border:1px solid #369; background:#fff; font:12px/20px Arial;}.mailListDefault{padding:0 5px;cursor:pointer;white-space:nowrap;}.mailListFocus{padding:0 5px;cursor:pointer;white-space:nowrap;background:#369;color:white;}.mailListHlignt{color:red;}.mailListFocus .mailListHlignt{color:#fff;}</style>').appendTo($("head"));
}
var cb = , cl = , cf = , cm = ; //Plugin's class variable
var z = , newArr = mailArr = , hint = , text = , fc = , bc = ;
//Create internal list content of the email
$.createHtml = function(str, arr, cur){
var mailHtml = "";
if($.isArray(arr)){
$.each(arr, function(i, n){
if(i === cur){
mailHtml += '<div class="mailHover '+cf+'" ><span class="'+cm+'">'+str+'</span>@'+arr[i]+'</div>';
}else{
mailHtml += '<div class="mailHover '+cl+'" ><span class="'+cm+'">'+str+'</span>@'+arr[i]+'</div>';
}
});
}
return mailHtml;
};
//Some global variables
var index = -1, s;
$(this).each(function(){
var that = $(this), i = $(".justForJs").size();
if(i > 0){ //Bind only one text box
return;
}
var w = (), h = (); //Get the width and height of the current object (i.e. text box)
//Style initialization
('<span style="display:inline-block;position:relative;"></span>')
.before('<div class="justForJs '+cb+'" style="min-width:'+w+'px;_width:'+w+'px;position:absolute;left:-6000px;top:'+h+'px;z-index:'+z+';"></div>');
var x = $("#mailListBox_" + i), liveValue; //Listbox object
(function(){
//The level of parent tag
$(this).css("color", fc).parent().css("z-index", z);
//Show and hide prompt text
if(hint && text){
var focus_v = $.trim($(this).val());
if(focus_v === text){
$(this).val("");
}
}
//Keyboard event
$(this).keyup(function(e){
s = v = $.trim($(this).val());
if(/@/.test(v)){
s = (/@.*/, "");
}
if( > 0){
//If the key is up and down key
if( === 38){
//up
if(index <= 0){
index = ;
}
index--;
}else if( === 40){
//down
if(index >= - 1){
index = -1;
}
index++;
}else if( === 13){
//Enter
if(index > -1 && index < ){
//If there is currently an activation list
$(this).val($("#mailList_"+index).text());
}
}else{
if(/@/.test(v)){
index = -1;
//Get the value after @
//s = (/@.*/, "");
//Create a new matching array
var site = (/.*@/, "");
newArr = $.map(mailArr, function(n){
var reg = new RegExp(site);
if((n)){
return n;
}
});
}else{
newArr = mailArr;
}
}
($.createHtml(s, newArr, index)).css("left", 0);
if( === 13){
//Enter
if(index > -1 && index < ){
//If there is currently an activation list
("left", "-6000px");
}
}
}else{
("left", "-6000px");
}
}).blur(function(){
if(hint && text){
var blur_v = $.trim($(this).val());
if(blur_v === ""){
$(this).val(text);
}
}
$(this).css("color", bc).unbind("keyup").parent().css("z-index",0);
("left", "-6000px");

});
//The mouse passes the list item event
//The mouse passes
$(".mailHover").live("mouseover", function(){
index = Number($(this).attr("id").split("_")[1]);
liveValue = $("#mailList_"+index).text();
("." + cf).removeClass(cf).addClass(cl);
$(this).addClass(cf).removeClass(cl);
});
});

("mousedown", function(){
(liveValue);
});
});
};

})(jQuery);