在这里奉上源代码,没有做样式处理,不过功能是可以的,希望大家可以和我交流交流!
复制代码 代码如下:
<html>
<head>
<title>点击弹出DIV选择信息</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<input type="text" onfocus="alertDivINFO(this, 'id', 'name', true, true, 600, 300, 'arrs')" />
<div style="position: absolute;"></div>
</body>
</html>
<script type="text/javascript">
//数组信息
var arrs = new Array();
arrs.push({id:"1", name:"张三3"});
arrs.push({id:"2", name:"李四3"});
arrs.push({id:"3", name:"申午武3"});
arrs.push({id:"4", name:"周琬淞3"});
arrs.push({id:"5", name:"覃晓为3"});
arrs.push({id:"6", name:"王五"});
arrs.push({id:"7", name:"宝典3"});
/**
* obj: 点击文本框的对象
* idStr: json数组的id键名
* nameStr: json数组的name键名
* bool: true:表示追加 false:表示重新赋值
* boolSet: true:ID和Name的值都显示 false:只显示Name的值
* widthNum: 信息DIV的宽度
* heightNum: 信息DIV的高度
* arrName: 数组名称
*/
function alertDivINFO(obj, idStr, nameStr, bool, boolSet, widthNum, heightNum, arrName){
obj.blur();
if(!widthNum){
widthNum = 600;
}
if(!heightNum){
heightNum = 350;
}
//创建大的DIV
var alertDivParent = document.createElement("div");
alertDivParent.id = "alertDivParent";
with(alertDivParent.style){
top = 0;
left = 0;
position = "absolute";
background = "#EEEEEE";
filter = "alpha(opacity=70)";
opacity = 0.7;
width = Math.max(document.body.clientWidth, document.body.scrollWidth);
height = Math.max(document.body.clientHeight, document.body.scrollHeight);
}
document.body.appendChild(alertDivParent);
//创建小的DIV
var alertDiv = document.createElement("div");
alertDiv.id = "alertDiv";
with(alertDiv.style){
width = widthNum;
height = heightNum;
position = "absolute";
background = "#DDDDDD";
left = (Math.max(document.body.clientWidth, document.body.scrollWidth) - widthNum) / 2;
top = (Math.max(document.body.clientHeight, document.body.scrollHeight) - heightNum) / 2;
}
//添加到窗体
document.body.appendChild(alertDiv);
//创建搜索的DIV
var alertQueryDiv = document.createElement("div");
alertQueryDiv.id = "alertQueryDiv";
//将搜索的DIV添加到信息DIV
alertDiv.appendChild(alertQueryDiv);
alertQueryDiv.innerHTML = "搜索 名称:";
//创建文本框
var alertQueryINPUT = document.createElement("input");
alertQueryINPUT.id = "alertQueryINPUT";
alertQueryINPUT.type = "text";
//将文本框添加到搜索的DIV
alertQueryDiv.appendChild(alertQueryINPUT);
//创建搜索按钮
var alertQueryBUTTON = document.createElement("input");
alertQueryBUTTON.id = "alertQueryBUTTON";
alertQueryBUTTON.type = "button";
alertQueryBUTTON.value = " 搜 索 ";
//给按钮添加事件
alertQueryBUTTON.onclick = function(){
//计算该宽度可放多少单元格
var tdWidthNum = 130;
var tdNum = parseInt(widthNum / tdWidthNum);
var num = 0;
var j = 0;
//获取显示信息的Table
var alertInfoTab = document.getElementById("alertInfoTab");
//清空THead的信息
alertInfoTab.deleteTHead();
//循环数组
for(var i = 0; i < eval(arrName).length; i ++){
//如果与数组中的相等就添加到TABLE
if(eval(arrName + "[i]." + nameStr).indexOf(alertQueryINPUT.value) >= 0){
var header;
if(j % tdNum == 0){
header = alertInfoTab.createTHead();
header = header.insertRow(num);
num ++;
}
j ++;
var headerName = header.insertCell(-1);
with(headerName.style){
width = tdWidthNum;
color = "blue";
cursor = "pointer";
}
if(boolSet)
headerName.appendChild(document.createTextNode(eval(arrName + "[i]." + idStr) + ": " + eval(arrName + "[i]." + nameStr)));
else if(!boolSet)
headerName.appendChild(document.createTextNode(eval(arrName + "[i]." + nameStr)));
headerName.onclick = function(){
if(bool)
obj.value = obj.value + this.innerHTML + ";";
else if(!bool)
obj.value = this.innerHTML;
//移除弹出的窗体
document.body.removeChild(alertDiv);
document.body.removeChild(alertDivParent);
};
}
}
};
//将按钮添加到搜索的DIV
alertQueryDiv.appendChild(alertQueryBUTTON);
//创建清空按钮
var alertClearBUTTON = document.createElement("input");
alertClearBUTTON.id = "alertClearBUTTON";
alertClearBUTTON.type = "button";
alertClearBUTTON.value = " 清 空 ";
alertClearBUTTON.onclick = function(){
//给文本框赋空值
obj.value = "";
//移除弹出的窗体
document.body.removeChild(alertDiv);
document.body.removeChild(alertDivParent);
};
//将按钮添加到搜索的DIV
alertQueryDiv.appendChild(alertClearBUTTON);
//创建关闭按钮
var alertCancelBUTTON = document.createElement("input");
alertCancelBUTTON.id = "alertCancelBUTTON";
alertCancelBUTTON.type = "button";
alertCancelBUTTON.value = " 关 闭 ";
alertCancelBUTTON.onclick = function(){
//移除弹出的窗体
document.body.removeChild(alertDiv);
document.body.removeChild(alertDivParent);
};
//将按钮添加到搜索的DIV
alertQueryDiv.appendChild(alertCancelBUTTON);
//创建显示信息的Table
var alertInfoTab = document.createElement("table");
alertInfoTab.id = "alertInfoTab";
with(alertInfoTab.style){
margin = 20;
}
//计算该宽度可放多少单元格
var tdWidthNum = 130;
var tdNum = parseInt(widthNum / tdWidthNum);
var num = 0;
for(var i = 0; i < eval(arrName).length; i ++){
var header;
if(i % tdNum == 0){
header = alertInfoTab.createTHead();
header = header.insertRow(num);
num ++;
}
var headerName = header.insertCell(-1);
with(headerName.style){
width = tdWidthNum;
color = "blue";
cursor = "pointer";
}
//var headerType = header.insertCell(-1);
if(boolSet)
headerName.appendChild(document.createTextNode(eval(arrName + "[i]." + idStr) + ": " + eval(arrName + "[i]." + nameStr)));
else if(!boolSet)
headerName.appendChild(document.createTextNode(eval(arrName + "[i]." + nameStr)));
//headerType.appendChild(document.createTextNode("Type"));
headerName.onclick = function(){
if(bool)
obj.value = obj.value + this.innerHTML + ";";
else if(!bool)
obj.value = this.innerHTML;
//移除弹出的窗体
document.body.removeChild(alertDiv);
document.body.removeChild(alertDivParent);
};
}
//将table添加到显示信息的DIV
alertDiv.appendChild(alertInfoTab);
}
</script>
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]