网页对话框:自己定制网页对话框来源: 发布时间:星期四, 2009年2月12日 浏览:512次 评论:0
当 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 1.按纽 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 2.默认 ![]() ![]() ![]() ![]() 下面说 ![]() ![]() 1.需要将默认项设置给“OK”按纽的外 ![]() ![]() 2.需要改变默认按纽 ![]() ![]() ![]() 我应该提醒 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() =Title> ![]() [ 返回页首 ] 让我们来检验 ![]() ![]() ![]() ![]() ![]() 1. 3个div层 2.两个Web服务器Control控件(按纽) 代码清单1 =Code> <div id=\"divConfMessage\" runat=\"server\" style=\"BORDER-RIGHT:black thin solid; BORDER-TOP:black thin solid; DISPLAY:none; Z-INDEX:200; BORDER-LEFT:black thin solid; BORDER-BOTTOM:black thin solid\"> <div style=\"BACKGROUND-COLOR: #6699cc;TEXT-ALIGN: center\" id=\"confirmText\"> </div> <div style=\"Z-INDEX: 105;HEIGHT: 2%;BACKGROUND-COLOR: white;TEXT-ALIGN: center\"> </div> <div style=\"Z-INDEX: 105;BACKGROUND-COLOR: white;TEXT-ALIGN: center\"> <asp:Button ID=\"btnConfOK\" Runat=\"server\" Text=\"OK\"></asp:Button> <asp:Button ID=\"btnConfCancel\" Runat=\"server\" Text=\"Cancel\"></asp:Button> </div> </div> 以上清单将创建 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 需要注意 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() JavaScript 代码 在这部分我们将创建 ![]() ![]() ![]() ![]() 1.全局变量(4个) a-var divWidth=\'\';这个变量用来设置对话框 ![]() ![]() b-var divHeight=\'\';这个变量用来设置对话框 ![]() ![]() c-var txtFirstButton=OK;这个变量用来设置第 ![]() ![]() ![]() d-var txtSecondButton=Cancel;这个变量用来设置第 2个按纽 ![]() ![]() 2. ![]() a-DisplayConfirmMessage(msg,width,height) b-SetTopLeft(divLayer) c-SetText(txtButton1,txtButton2) d-SetHeightWidth(divLayer) f-SetDefaultButton(defaultButton) 代码清单2 =Code> 以上 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 对层设置完高度、宽度、居上和居右属性后 ![]() ![]() 注意window.onresize ![]() ![]() ![]() ![]() ![]() 代码最后 ![]() ![]() ![]() 代码清单3 function SetTopLeft(divLayer) { // Get the dialogbox height var divHeightPer = divLayer.style.height.split(\'px\')[0]; // Set the top variable var top = (parseInt(document.body.off ![]() // Get the dialog box width var divWidthPix = divLayer.style.width.split(\'px\')[0]; // Get the left variable var left = (parseInt(document.body.off ![]() / 2); // ![]() divLayer.style.position = \'absolute\'; // Set the div top to the height divLayer.style.top = top // Set the div Left to the height divLayer.style.left = left; } 以上 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 代码清单4 function SetHeightWidth(divLayer) { // Set the dialogbox width divLayer.style.width = divWidth + \'px\'; // Set the dialogbox Height divLayer.style.height = divHeight + \'px\' } 以上清单是设置对话框 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 代码清单5 function SetText(txtButton1, txtButton2) { // Set display text for the two buttons ![]() ![]() document.getElementById(\'btnConfOK\').innerText = txtFirstButton; ![]() document.getElementById(\'btnConfOK\').innerText = txtButton1;[Page] // Set display text for the two buttons ![]() ![]() document.getElementById(\'btnConfCancel\').innerText = txtSecondButton; ![]() document.getElementById(\'btnConfCancel\').innerText = txtButton2; } 以上清单用来显示两个按纽 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 代码清单6 function SetDefaultButton(defaultButton) { // Set the focus _disibledevent=>执行步骤 [ 返回页首 ] function DisplayConfirmMessage(msg, width, height) { // Set default dialogbox width ![]() ![]() ![]() divWidth = 180 ![]() divWidth = width; // Set default dialogBox height ![]() ![]() ![]() divHeight = 90 ![]() divHeight = height; // Ge the dialogbox object var divLayer = document.getElementById(\'divConfMessage\'); // Set dialogbox height and width SetHeightWidth(divLayer) // Set dialogbox top and left SetTopLeft(divLayer); // Show the div layer divLayer.style.display = \'block\'; // Change the location and re ![]() ![]() window.onresize = function ![]() { ![]() ![]() { SetTopLeft(divLayer); SetHeightWidth(divLayer) } } // Set the dialogbox display message document.getElementById (\'confirmText\').innerText = msg; } 在这部分中你将学到如何将这个对话框添加到你 ![]() ![]() ![]() ![]() ![]() 在根文件夹下创建 ![]() ![]() ![]() ![]() ![]() ![]() 代码清单7 <script language=\"javascript\" src=\"CustomDialog.js\"></script> 以上代码将链接到你已经创建到webform项目中 ![]() ![]() ![]() ![]() ![]() 代码清单8 <script language = JavaScript> function ShowMessage ![]() { SetText(\'Yes\', \'No\'); DisplayConfirmMessage(\'are you sure\', 180, 90)[Page] SetDefaultButton(\'btnConfOK\'); ![]() } </script> 首先要做 ![]() ![]() ![]() ![]() 代码清单9 Button1.Attributes.Add(\"onclick\",\" ![]() ![]() 图形1 以上图片显示当用户点击按纽时 ![]() ![]() ![]() 图形2 以上图片显示当窗口大小改变时 ![]() ![]() [ 返回页首 ] [源码下载] 1
相关文章读者评论发表评论 |