jquery jquery-confirm的使用

<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
  <script src='./jquery-3.4.1.min.js'></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
  <meta charset="utf-8" />
</head>

<body>

  <button class="btn">点击</button>

</body>

<script>

  $(function() {

    $("button.btn").click(function(){

      $.confirm({
        title: '你确定要做这个事情吗',
        content: '你做的事情可能造成IT行业的科技革命',
        buttons: {
          ok: {
            text: '确定',
            btnClass: 'btn-primary',
            action: function() {
              console.log('同意')
            }
          },
          cancel: {
            text: '取消',
            brnClass: 'btn-primary',
            action: function() {
              console.log('取消')
            }
          }
        }
      })

    })


  })
</script>

</html>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我可以为你提供一个示例代码,使用 jquery-confirm 插件实现弹出框缩小后出现在右侧边缘,恢复后出现在中间区域。 首先,你需要引入 jquery-confirm 插件和 jQuery 库。然后,使用以下代码创建一个弹出框: ```html <div id="my-confirm" class="my-confirm"> <h4>提示</h4> <p>这是一个弹出框</p> </div> ``` 接下来,你可以使用以下 JavaScript 代码初始化 jquery-confirm 插件,并设置弹出框缩小和恢复的回调函数: ```javascript $(document).ready(function() { // 初始化 jquery-confirm 插件 $.confirm({ title: '', content: $('#my-confirm'), columnClass: 'medium', draggable: true, dragWindowGap: 0, onContentReady: function() { var self = this; this.$content.find('.btn-minimize').click(function() { // 缩小弹出框 self.$content.parent().removeClass('medium').addClass('small'); self.$content.parent().css({ top: $(window).height() - self.$content.parent().outerHeight() - 50, left: $(window).width() - self.$content.parent().outerWidth() - 50 }); }); this.$content.find('.btn-maximize').click(function() { // 恢复弹出框 self.$content.parent().removeClass('small').addClass('medium'); self.$content.parent().css({ top: ($(window).height() - self.$content.parent().outerHeight()) / 2, left: ($(window).width() - self.$content.parent().outerWidth()) / 2 }); }); } }); }); ``` 在这个示例中,我们首先初始化了 jquery-confirm 插件,并使用 content 属性指定了弹出框的内容。然后设置 draggable 属性为 true,允许用户拖动弹出框。同时设置 dragWindowGap 属性为 0,使弹出框拖动时与鼠标指针对齐。 接着,我们在 onContentReady 回调函数中获取弹出框的按钮元素,并为按钮元素绑定了 click 事件。在缩小按钮的 click 事件中,我们使用 jQuery 的 css() 方法设置了弹出框的位置,使其出现在右侧边缘。在恢复按钮的 click 事件中,我们同样使用 css() 方法设置了弹出框的位置,使其出现在中间区域。 最后,我们在 HTML 中为弹出框添加了两个按钮,分别是缩小和恢复按钮: ```html <button class="btn-minimize">缩小</button> <button class="btn-maximize">恢复</button> ``` 希望这个示例代码能够帮助你实现弹出框缩小后出现在右侧边缘,恢复后出现在中间区域的效果。如果还有其他问题,欢迎继续提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值