首页 > web前端 > js教程 > 正文

重点分析JavaScript重写alert()方法的技巧

亚连
发布: 2018-05-17 10:02:28
原创
2713人浏览过

重点分析JavaScript重写alert()方法的技巧

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

window.alert = function(str) { 

    var alertBox = document.createElement("div"); 

    alertBox.id="alertBox"

    alertBox.style.position = "absolute"

    alertBox.style.width = "400px"

    alertBox.style.background = "#F2F2F2"

    alertBox.style.border = "1px solid grey"

    alertBox.style.left = "50%"

    alertBox.style.top = "50%"

    alertBox.style.transform = "translate(-50%, -50%)"

    alertBox.style.textAlign = "center"

    alertBox.style.zIndex = "100"

    var strHtml = ""

    strHtml += '<div id="title">提示:<div id="close" onclick="certainFunc()"></div></div>'

    strHtml += '<div id="content">'+str+'</div>'

    strHtml += '<div id="certain"><input id="btn" type="button" value="确 定" onclick="certainFunc()" onhover="hoverFunc()"/></div>'

    alertBox.innerHTML = strHtml; 

    document.body.appendChild(alertBox); 

    var title = document.getElementById("title"); 

    title.style.textAlign = "left"

    title.style.marginTop = "20px"

    title.style.paddingLeft = "20px"

    title.style.height = "30px"

    title.style.fontSize = "15px"

    var close = document.getElementById("close"); 

    close.style.width = "16px"

    close.style.height = "16px"

    close.style.marginRight = "20px"

    close.style.background = "url('images/close.png')"

    close.style.float = "right"

    var content = document.getElementById("content"); 

    content.style.margin = "20px"

    content.style.fontSize = "12px"

    var certain = document.getElementById("certain"); 

    certain.style.position = "relative"

    certain.style.height = "50px"

    certainFunc = function() { 

        alertBox.parentNode.removeChild(alertBox); 

    }; 

    var btn = document.getElementById("btn"); 

    btn.style.width = "60px"

    btn.style.height = "30px"

    btn.style.background = "#cccccc"

    btn.style.border = "1px solid grey"

    btn.style.position = "absolute"

    btn.style.borderRadius = "5px"

    btn.style.right = "20px"

    btn.style.bottom = "20px"

    btn.style.marginTop = "10px"

    btn.style.cursor = "pointer"

    btn.style.color = "#333"

    hoverFunc = function() { 

        btn.style.border = "1px blue solid"

    }; 

}

登录后复制

上面是我整理的重点分析javascript重写alert()方法的技巧给大家的,希望今后会对大家有帮助。

相关文章:

js解析数据技巧总结

原生JS封装淡入淡出效果函数步骤详解

在vue项目中使用sass的配置方法_vue.js

以上就是重点分析JavaScript重写alert()方法的技巧的详细内容,更多请关注php中文网其它相关文章!

java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号