在Bootstrap模式中实现jQuery DatePicker。

时间:2022-11-30 11:14:16

Created jsfiddle for my issue http://jsfiddle.net/sudiptabanerjee/93eTU/

为我的问题http://jsfiddle.net/sudiptabanerjee/93eTU/创建jsfiddle

In modal window issue is on Change Month and Change Year combos.

在模式窗口期的问题是变化月和变化年组合。

a) IE 11: everything is working as expected b) Chrome Version 31, On month combo select, bootstrap modal hides. c) Firefox v26, Month and Year dropdown is not functional.

a) IE 11:一切都按照预期运行b) Chrome 31版本,在月组合选择,引导模式隐藏。c) Firefox v26,月/年下拉没有功能。

Please help.

请帮助。

HTML

HTML

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
             <h4 class="modal-title" id="myModalLabel">Modal title</h4>

        </div>
        <div class="modal-body">
            <div class="col-md-12">
                <div class="row">
                    <label for="idTourDateDetails">Tour Start Date:</label>
                    <div class="form-group">
                        <div class="input-group">
                            <input type="text" name="idTourDateDetails" id="idTourDateDetails" readonly="readonly" class="form-control clsDatePicker"> <span class="input-group-addon"><i id="calIconTourDateDetails" class="glyphicon glyphicon-th"></i></span>

                        </div>
                    </div>Alt Field:
                    <input type="text" name="idTourDateDetailsHidden" id="idTourDateDetailsHidden">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

CSS

CSS

.clsDatePicker {
z-index: 100000;
}

JS

JS

 $('#idTourDateDetails').datepicker({
 dateFormat: 'dd-mm-yy',
 minDate: '+5d',
 changeMonth: true,
 changeYear: true,
 altField: "#idTourDateDetailsHidden",
 altFormat: "yy-mm-dd"
});

4 个解决方案

#1


47  

This is because the modal enforces focus on itself. Here is a solution for this as mentioned here . Add the below script to your js file. That's it.

这是因为模态执行力专注于自身。这里有一个解决方法。将下面的脚本添加到js文件中。就是这样。

Working Demo

演示工作

jQuery

jQuery

// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results 
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;

$.fn.modal.Constructor.prototype.enforceFocus = function() {};

$confModal.on('hidden', function() {
    $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
});

$confModal.modal({ backdrop : false });

#2


3  

jQuery version of @crftr answer

@crftr答案的jQuery版本

var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
try{
    $confModal.on('hidden', function() {
        $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
    });
    $confModal.modal({ backdrop : false });
}
catch (error) {
    if(error.name != 'ReferenceError')
        throw error;
}

#3


1  

MORE EASY... just need to comment this line into your boostrap.js that.enforceFocus().

更容易……只需将这一行注释到你的boostrap中。js that.enforceFocus()。

#4


0  

Building off of Surjith's answer, I added a try/catch block to resolve a ReferenceError exception for confModal being undefined.

根据Surjith的答案,我添加了一个try/catch块,以解决未定义的confModal的一个ReferenceError异常。

Coffeescript:

Coffeescript:

enforceModalFocusFn = $.fn.modal.Constructor::enforceFocus

$.fn.modal.Constructor::enforceFocus = ->

try
  $confModal.on "hidden", ->
    $.fn.modal.Constructor::enforceFocus = enforceModalFocusFn
    return
  $confModal.modal backdrop: false
catch error
  if error.name != 'ReferenceError'
    throw error

#1


47  

This is because the modal enforces focus on itself. Here is a solution for this as mentioned here . Add the below script to your js file. That's it.

这是因为模态执行力专注于自身。这里有一个解决方法。将下面的脚本添加到js文件中。就是这样。

Working Demo

演示工作

jQuery

jQuery

// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results 
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;

$.fn.modal.Constructor.prototype.enforceFocus = function() {};

$confModal.on('hidden', function() {
    $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
});

$confModal.modal({ backdrop : false });

#2


3  

jQuery version of @crftr answer

@crftr答案的jQuery版本

var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
try{
    $confModal.on('hidden', function() {
        $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
    });
    $confModal.modal({ backdrop : false });
}
catch (error) {
    if(error.name != 'ReferenceError')
        throw error;
}

#3


1  

MORE EASY... just need to comment this line into your boostrap.js that.enforceFocus().

更容易……只需将这一行注释到你的boostrap中。js that.enforceFocus()。

#4


0  

Building off of Surjith's answer, I added a try/catch block to resolve a ReferenceError exception for confModal being undefined.

根据Surjith的答案,我添加了一个try/catch块,以解决未定义的confModal的一个ReferenceError异常。

Coffeescript:

Coffeescript:

enforceModalFocusFn = $.fn.modal.Constructor::enforceFocus

$.fn.modal.Constructor::enforceFocus = ->

try
  $confModal.on "hidden", ->
    $.fn.modal.Constructor::enforceFocus = enforceModalFocusFn
    return
  $confModal.modal backdrop: false
catch error
  if error.name != 'ReferenceError'
    throw error

相关文章