WEB开发网
开发学院网页设计JavaScript javascript中alert函数的替代方案,一个自定义的对... 阅读

javascript中alert函数的替代方案,一个自定义的对话框的方法

 2010-03-24 00:00:00 来源:WEB开发网   
核心提示: 接下来,我们创建对话框的标题栏,javascript中alert函数的替代方案,一个自定义的对话框的方法(5),这个用来显示对话框的标题,并且用它了实现对话框的拖动操作

接下来,我们创建对话框的标题栏,这个用来显示对话框的标题,并且用它了实现对话框的拖动操作。

 1 var divHead = document.createElement("div");
 2 if (title != undefined) {
 3     divHead.innerHTML = title;
 4 } else {
 5     divHead.appendChild(document.createTextNode("消息"));
 6 }
 7 divHead.style.width = "100%";
 8 divHead.style.height = "25px";
 9 divHead.style.lineHeight = "25px";
10 divHead.style.fontSize = "14px";        
11 divHead.style.fontWeight = "bold";
12 divHead.style.borderBottom = "1px outset #8989FF";
13 divHead.style.color = "white";
14 divHead.style.textIndent = "10px";
15 divHead.style.backgroundColor = "blue";
16 divHead.style.backgroundImage = "url('" + springweb_basePath  + "/images/headbg.png')";
17 divHead.style.cursor = "move";
18 divHead.onmousedown = function() {
19 
20     divDialog.dragging = true;
21     
22 };
23 divHead.onmouseup = function() {
24 
25     divDialog.dragging = false;
26 
27 };
28 
29 document.body.onmousemove = function(e) {
30 
31     if (!divDialog.dragging) return;
32     e = e || window.event;
33     var mouseX, mouseY;
34     var mouseOffsetX, mouseOffsetY;
35     if (e.pageX || e.pageY) {
36         mouseX = e.pageX;
37         mouseY = e.pageY;
38 
39     } else {
40         mouseX =
41             e.clientX + document.body.scrollLeft -
42             document.body.clientLeft;
43         mouseY =
44             e.clientY + document.body.scrollTop -
45             document.body.clientTop;
46 
47     }
48     
49     divDialog.style.left = (mouseX - dialogWidth * 0.4) + "px";
50     divDialog.style.top = (mouseY - 10) + "px";            
51 };
52         
53 
54 divDialog.appendChild(divHead);

上一页  1 2 3 4 5 6  下一页

Tags:javascript alert 函数

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接