jquery-confirm 对话框中的 jQuery UI 日期选择器

2024-03-19

我正在使用下面链接中的 jquery-confirm 脚本。它能够在对话框中包含表单字段。您可以通过单击下面链接中的“按提示操作”蓝色按钮来查看此内容。

我已经设置了表单(单个字段),但我希望这个输入是一个日期选择器,并且我不知道应该在哪里放置 javascript 来实现这一点,因为在对话框出现之前此表单不存在被生成。

https://craftpip.github.io/jquery-confirm/ https://craftpip.github.io/jquery-confirm/

我的对话框 JavaScript:

            $('.deal_edit').on('click', function () {
            var id = $(this).attr('data-id');
            $.confirm({
                title: 'Change end Date',
                content: 'url:form.txt',
                confirm: function () {
                    var input = this.$b.find('input#new_end_date').val();
                    var errorText = this.$b.find('.text-danger');
                    if (input.val() == '') {
                        errorText.show();
                        return false;
                    } else {
                        var data = {action: 'edit_deal', id: id, new_date: new_date};
                        $.post('ajax.php', data, function(response) {

                            $.alert({
                                title: "Updated",
                                content: "Ok, record has been updated - this page will reload.",
                                confirm: function() {
                                    location.reload();
                                }   
                            });

                        });
                    }
                }
            });
            return false;
        });     

form.txt的内容:

<p>The only editable field currently is 'deal end date'.  (This may change soon)</p>
<div class="form-group">
  <label>New End Date</label>
  <input autofocus type="text" id="new_end_date" name="new_end_date" class="form-control">
</div>
     <p class="text-danger" style="display:none">Please enter an end date, or click 'close'.</p>

谢谢你!!!


我有同样的问题,这就是我解决它的方法。

需要在确认对话框中添加 onOpen 和 onClose 事件来添加

        $.confirm({
            onOpen: function(){
                $( ".datepicker" ).datepicker();
            },
            onClose: function(){
                $(".datepicker").datepicker("destroy");
            },
            title: 'Change end Date',
            content: 'url:form.txt',
            confirm: function () {
                var input = this.$b.find('input#new_end_date').val();
                var errorText = this.$b.find('.text-danger');
                if (input.val() == '') {
                    errorText.show();
                    return false;
                } else {
                    var data = {action: 'edit_deal', id: id, new_date: new_date};
                    $.post('ajax.php', data, function(response) {

                        $.alert({
                            title: "Updated",
                            content: "Ok, record has been updated - this page will reload.",
                            confirm: function() {
                                location.reload();
                            }   
                        });

                    });
                }
            }
        });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jquery-confirm 对话框中的 jQuery UI 日期选择器 的相关文章

随机推荐