【问题标题】:How to Add a CountDown Timer inside a jQuery Dialog Button如何在 jQuery 对话框按钮中添加倒数计时器
【发布时间】:2017-05-11 15:41:39
【问题描述】:

我试图弄清楚如何在 jQuery UI 对话框的按钮文本中添加倒计时,但找不到任何东西。一段时间后,我编写了一个解决问题的方法。

【问题讨论】:

  • 这里真的没有问题。这更像是“看看我做了什么”。这当然很有帮助,但不适合 Q 和 A 模型。

标签: javascript jquery onclick dialog countdown


【解决方案1】:

以下是执行此操作的代码:

function jqAlert(message, time) {
            var counter = time;
            $( "#dialog" ).dialog({
               title: "Message From Web App",
               modal: true,
               resizable: true,
               autoOpen: true, 
               modal: true,
               buttons: {
                    "OK": {
                        text: "OK (" + (time / 1000)+ ")" ,
                        id: "btnDialogOK",
                        click: function(){
                            $('#dialog').dialog('close');
                        }
                    }
               },
               open: function(event, ui) {
                    countdown(time);
                    $(this).html(message);
                    setTimeout(function(){
                        $('#dialog').dialog('close');                
                    }, time);
                }
            });
         } 
         function countdown(time) {
            var timeleft = (time / 1000);
            var downloadTimer = setInterval(function(){
            timeleft--;
            document.getElementById("btnDialogOK").style.padding = "7px 18px 7px 18px";
            document.getElementById("btnDialogOK").textContent = "OK " + "(" + timeleft + ")";
            if(timeleft <= 0)
                clearInterval(downloadTimer);
            },1000);      
         }

从 onclick 中调用 jqAlert 方法:

jqAlert("This is an Alert", 5000);

【讨论】:

  • 真的吗???你有什么问题?如果你已经有了答案,为什么还要问?
  • 我认为这应该是一个教程。
猜你喜欢
  • 1970-01-01
  • 2011-10-05
  • 2021-05-01
  • 2011-01-31
  • 1970-01-01
  • 1970-01-01
  • 2023-04-11
  • 2012-04-07
  • 2010-12-01
相关资源
最近更新 更多