在这里奉上源代码,没有做样式处理,不过功能是可以的,希望大家可以和我交流交流!
代码如下:
<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");
新闻热点
疑难解答
图片精选