這篇文章主要介紹了javascript彈出層輸入框(示例代碼)。需要的朋友可以過來參考下,希望對大家有所幫助
如下所示: 代碼如下: <script language="javascript" type="text/javascript"> function alertWin(title, msg, w, h) { var titleheight = "22px"; // 窗口標題高度 var bordercolor = "#666699"; //窗口的邊框顏色 var titlecolor = "#FFFFFF"; // 窗口的標題顏色 var titlebgcolor = "#666699"; // 窗口的標題背景色 var bgcolor = "#FFFFFF"; // 內容背景色 var iWidth = document.documentElement.clientWidth; //這個窗口的寬度 var iHeight = document.documentElement.clientHeight; //這個窗口的高度 //背景層的格式 var bgObj = document.createElement("div"); bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:" + iWidth + "px;height:" + Math.max(document.body.clientHeight, iHeight) + "px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:1000;"; document.body.appendChild(bgObj); var iframe2 = document.createElement("iframe"); iframe2.style.cssText = "position:absolute; top:0px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000; z-index:1001; border-style:none; border-width:0px; border:0px;width:" + iWidth + "px;height:" + iHeight + "px"; bgObj.appendChild(iframe2); //創建一個彈出層 var msgObj = document.createElement("div"); //設置彈出的層的樣式 msgObj.style.cssText = "position:absolute;font:11px '宋體';top:" + (iHeight - h) / 2 + "px;left:" + (iWidth - w) / 2 + "px;width:" + w + "px;height:" + h + "px;text-align:center;border:1px solid " + bordercolor + ";background-color:" + bgcolor + ";padding:1px;line-height:22px;z-index:1001;"; document.body.appendChild(msgObj); //創建一個table用於容納層上的內容 var table = document.createElement("table"); //將Table放到彈出層上 msgObj.appendChild(table); //設置table的格式 table.style.cssText = "margin:0px;border:0px;padding:0px;"; table.cellSpacing = 0; //插入一行用於顯示標題 var tr = table.insertRow(-1); //插入一個單元格用於容納標題 var titleBar = tr.insertCell(-1); titleBar.style.cssText = "width:100%;height:" + titleheight + "px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋體';color:" + titlecolor + ";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor; titleBar.style.paddingLeft = "10px"; //設置標題 titleBar.innerHTML = title; //設置曾德拖動事件 var moveX = 0; var moveY = 0; var moveTop = 0; var moveLeft = 0; var moveable = false; var docMouseMoveEvent = document.onmousemove; var docMouseUpEvent = document.onmouseup; //鼠標點擊標題 titleBar.onmousedown = function() { var evt = getEvent(); moveable = true; moveX = evt.clientX; moveY = evt.clientY; moveTop = parseInt(msgObj.style.top); moveLeft = parseInt(msgObj.style.left); //鼠標拖動 document.onmousemove = function() { if (moveable) { var evt = getEvent(); var x = moveLeft + evt.clientX - moveX; var y = moveTop + evt.clientY - moveY; if (x > 0 && (x + w < iWidth) && y > 0 && (y + h < iHeight)) { msgObj.style.left = x + "px"; msgObj.style.top = y + "px"; } } }; document.onmouseup = function() { if (moveable) { document.onmousemove = docMouseMoveEvent; document.onmouseup = docMouseUpEvent; moveable = false; moveX = 0; moveY = 0; moveTop = 0; moveLeft = 0; } }; } //關閉按鈕事件 var closeBtn = tr.insertCell(-1); closeBtn.style.cssText = "cursor:pointer; text-align:right;padding:2px;background-color:" + titlebgcolor; closeBtn.innerHTML = "<span style='font-size:15pt;color:" + titlecolor + ";'>×</span>"; closeBtn.onclick = function() { document.body.removeChild(bgObj); document.body.removeChild(msgObj); } //彈出的消息窗口內容 var msgBox = table.insertRow(-1).insertCell(-1); msgBox.style.cssText = "font:10pt '宋體';"; msgBox.colSpan = 2; msgBox.innerHTML = msg; //層上模板名稱的內容 var nameBox = table.insertRow(-1); var nameLable = nameBox.insertCell(-1); nameLable.style.cssText = "font:12pt '宋體';text-align:center;"; nameLable.innerHTML = "<br/>輸入身份證號:<br/>"; var nametext = nameBox.insertCell(-1); nametext.style.cssText = "font:12pt '宋體';text-align:Left; margin-left:0px"; nametext.innerHTML = "<br/><input type='text' value='' id='modalName'/> <br/>"; //層上動作按鈕的內容 var submitBox = table.insertRow(-1); var submitBtn = submitBox.insertCell(-1); submitBtn.style.cssText = "text-align:center;"; submitBtn.colSpan = 2; submitBtn.innerHTML = "<br/><input type='Button' value='確 定' id='saveHeader'onclick='return GetCark()' /><br/>"; function getEvent() { return window.event || arguments.callee.caller.arguments[0]; } } </script> <input type="button" value="存儲表頭" onclick="alertWin('身份信息采集','',300,150);" />