温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么实现点击HTML页面问号出现提示框

发布时间:2022-03-05 16:02:05 来源:亿速云 阅读:326 作者:iii 栏目:web开发

今天小编给大家分享一下怎么实现点击HTML页面问号出现提示框的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

本demo的功能:点击页面按钮在其边缘出现提示信息,点击页面任何一处则消失。

如下图:
怎么实现点击HTML页面问号出现提示框

1.所需插件:
  • jquery插件;

  • layer插件;

2.HTML内容:

==注意==:

  1. class="j-help-tips"这个class是核心,不可缺少。

  2. data-tips属性是必须的。

  3. data-tips属性中:type:"1"不用修改;

  4. data-tips属性中:txt内容即是要提示的内容。

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

<html>

    <head>

        <link rel="stylesheet" href="style.css"" type="text/css" />

    </head>

    

    <body>

        <div style="margin-top: 10%; margin-left: 10%;">

            <span class="testSpan">

                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"提示内容111..."}'>①</i>

            </span>

            

            <span style="margin: 30px;">

                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"提示内容222..."}'>②</i>

            </span>

            

            <span style="margin: 30px;">

                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"提示内容333..."}'>③</i>

            </span>

        </div>

    </body>

    

    <!-- jquery -->

    <script src="http://code.jquery.com/jquery-latest.js"></script>

    <!-- layer -->

    <script src="layer/layer.js" type="text/javascript"></script>

    <!-- 提示插件 -->

    <script src="script.js" type="text/javascript"></script>

    

    <script>

        $(function(){            <!-- 页面初始化加载 -->

            var tips = new helpTips().init();

        })    </script></html>

3.css内容:(非必要)
  • 本demo的css非必须,不影响功能;

1

2

3

4

5

6

7

8

9

10

.edi-icon {

    font-size: 18px;

    font-style: normal;

    -webkit-font-smoothing: antialiased;

    -webkit-text-stroke-width: .2px;

    -moz-osx-font-smoothing: grayscale;

    *display: inline;

    *zoom: 1;

    cursor: pointer;

}

4.javascript内容:(核心)

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

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

//定义提示弹出框;

var helpTipsLayer;

//定义弹出框的默认设置;

function helpTips(t) {

    this.options = {},

    this.options.elem = ".j-help-tips", //与页面class相对应;

    this.options.type = 1,

    this.options.color = "#8db3d7",

    this.options.time = 0, //设置0是提示弹出框不会自动消失;可设置为其他数字,以毫秒为单位;

    this.options.titleEnd = "录入提示",

    this.options.width = "600px",

    this.options.height = "",

    this.options.imgWidth = "233",

    this.options.imgHeight = "375",

    "undefined" != typeof t && (this.options = $.extend({}, this.options, t)),

    this.elemObj = $(this.options.elem)

}

!

function() {

    //点击页面任何一处可使提示弹出框消失;

    $(document).on("click", function(event){

        var e = event || window.event;

        var target = e.target || e.srcElement;

        var flag = $(target).hasClass("j-help-tips");

        if(helpTipsLayer && !flag){

            layer.close(helpTipsLayer);

        }

    })

}(), helpTips.prototype = {

    constructor : helpTips,

    init : function() {

        this.bindEvent()

    },

    bindEvent : function() {

        var t = this;

        t.elemObj.on("click", function() {

            layer.close(helpTipsLayer);//点击其他任意的提示框按钮,则关闭上一个提示框。

            var i = $(this),

                o = i.data("tips");

            if ("undefined" != typeof o && "undefined" != typeof o.type && 1 == o.type) {

                "undefined" != typeof o && "undefined" != typeof o.txt ? helpTipsLayer = layer.tips(o.txt, i, {

                    tips : [ t.options.type, t.options.color ],

                    time : t.options.time

                }) : t.log()

            } else {

                if ("undefined" != typeof o.title && "undefined" != typeof o.txt && "undefined" != typeof o.img) {

                    var e = '<p class="m-popup-ct">',

                        n = '<h4 class="tt"><span class="txt_01">' + o.title + t.options.titleEnd + '</span></h4><p class="line_01"></p>',

                        s = "</p>",

                        l = '<ul class="u-explain-list">',

                        p = o.txt.split("|"),

                        a = p.length;

                    a > 0 && $.each(p, function(t, i) {

                        l += '<li><i class="f-mr5">' + (t + 1) + "</i>" + i + "</li>"

                    });

                    var r = /^[1-9][\d]{0,2}$/,

                        c = t.options.imgWidth,

                        d = t.options.imgHeight;

                    "undefined" != typeof o.w && "undefined" != typeof o.h && r.test(o.w) && r.test(o.h) && (c = o.w, d = o.h), l += '<li><i class="f-mr5">' + (a + 1) + "</i><img src=" + o.img + ' width="' + c + '" height="' + d + '"/></li>', l += "</ul>";

                    var h = e + n + l + s;

                    layer.open({

                        title : !1,

                        type : 1,

                        area : [ t.options.width, t.options.height ],

                        shadeClose : !0,

                        maxmin : !1,

                        move : !1,

                        scrollbar : !1,

                        content : h

                    })

                } else {

                    t.log()

                }

            }

        })

    },

    log : function() {

        console.log("请给定提示标题|文字|图片---来自[script.js]函数[helpTips]")

    }

};

以上就是“怎么实现点击HTML页面问号出现提示框”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI