【问题标题】:When timer ends replaceWith当计时器结束时替换
【发布时间】:2016-03-04 11:24:19
【问题描述】:

我想确保当我的计时器结束时,我会收到一条消息而不是表单输入。一切正常。我只需要编写有效的 if 语句。这是我的代码:

var inputDate = new Date($('#count').val());
inputDate.setDate(inputDate.getDate());

$(".clock").countdown(inputDate, function(event) {
    $(this).text(event.strftime('%D dienos %Hh %Mmin %Ssek'));
    if (inputDate.val() == 0) {
        var statusHTML = '<p>Siūlymai nebegalimi. Aukciono laikas baigėsi.</p>';
        $("#placeBid").replaceWith(statusHTML);
    }
});

当我的计时器结束时,消息不会出现,表单仍然显示。如果我这样做:

if ($(".clock").val() == 0)

然后出现消息,但是当计时器没有结束时,它仍然显示消息而不是输入。

编辑 HTML 代码

        <form id="placeBid" action="/add-new-bid/{{$product->id}}" method="Post">

        {!! csrf_field() !!}

        <input type="submit" id="bidSubmit" class="btn btn-success" value="Siūlyti kainą" style="float: right" />

        <div style="overflow: hidden; padding-right: .5em;">
            <input type="hidden" value="{{$product->bid_price}}" id="jsBidPrice">

            <input style="width: 144px;" type="number" name="bid" class="minBid form-control" min="{{$product->bid_price}}" onkeyup="this.value = minmax(this.value, 0.01, 100)" placeholder="min. suma {{$product->bid_price}} €" style="width: 100%;" />

        </div>​
        </form>

【问题讨论】:

  • 我不知道你为什么要投反对票:)
  • 可以显示html代码吗?

标签: javascript jquery timer


【解决方案1】:

来自文档

Events

每当某些状态发生变化时,此插件都会触发一个事件,例如:

Update: Triggered to update the DOM
Finish: Triggered when finished
Stop: Triggered that paused

要注册回调,请使用以下 event.type:

update.countdown
finish.countdown
stop.countdown

请注意,所有事件都应使用命名空间 *.countdown 注册。

使用完成事件来获得你需要的东西?

顺便说一句。你在这里有很多信息: enter link description here

工作示例:

$('#clock').countdown('2016/03/04 13:01:00')
.on('finish.countdown', function(event) { 
**do all your shinigamis here**
});

【讨论】:

  • 不工作。我什至添加了这个日期:2016/03/03 00:01:00
  • 已修复。我需要 .clock 而不是 #clock :)
  • 上面的代码没问题,我在添加之前对其进行了测试。复制/粘贴文档中的示例之一,然后检查您在哪里做某事。错误的。顺便提一句。尝试通过 ID 而不是类来捕获您的元素。
猜你喜欢
  • 2023-01-11
  • 1970-01-01
  • 2016-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-05
  • 1970-01-01
  • 2020-11-30
相关资源
最近更新 更多