這篇文章主要介紹了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; &n