twitter-bootstrap 未捕获的类型错误:无法读取未定义的属性“拆分”-引导程序日期选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24780782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 21:07:39  来源:igfitidea点击:

Uncaught TypeError: Cannot read property 'split' of undefined - bootstrap datepicker

jquerytwitter-bootstrapdatepicker

提问by Lukeluha

i am using bootstrap datepicker for the input in bootstrap modal window. When I opened this windows for the first time, everything is ok and datepicker works fine. When I close this modal window and opened it again, my js console says Uncaught TypeError: Cannot read property 'split' of undefined

我正在使用引导程序日期选择器作为引导程序模式窗口中的输入。当我第一次打开这个窗口时,一切正常,日期选择器工作正常。当我关闭这个模态窗口并再次打开它时,我的 js 控制台说Uncaught TypeError: Cannot read property 'split' of undefined

I'm loading form in modal window with ajax.

我正在使用 ajax 在模态窗口中加载表单。

This is my modal window:

这是我的模态窗口:

<div id="finalModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">Final date</h3>
            </div>
            <div class="modal-body" id="finalModalBody">

            </div>
            <div class="modal-footer">
                <button id="finalSubmit" class="btn btn-success">Save</button>
            </div>

After loading this window, this script is started:

加载此窗口后,将启动此脚本:

$('.datepicker').datepicker({
           format: "dd.mm.yyyy"
})

And this is my formin modal window:

这是我的formin模式窗口:

<form>
<p><select onfocus="this.onmousewheel=function(){return false}" class="prereservationSelect" name="prereservation" id="frmfinalForm-prereservation"><option value="89">15. 7. 2014 - 19. 7. 2014</option><option value="0">second date</option></select></p>
<div id="otherDate" style="display: none">
    <p><strong><label for="frmfinalForm-otherDate">Zvolte jiny termín:</label></strong></p>
    <p style="float: left"><input type="text" class="datepicker text" name="otherDate" id="frmfinalForm-otherDate" value=""></p>
    <p style="margin-top: 15px; margin-left: 250px" id="date"></p>
</div>
</form>

Thanks for any advice.

感谢您的任何建议。

回答by stef

Try to change your selector to this:

尝试将您的选择器更改为:

$('#finalModal .datepicker').datepicker({
    format: "dd.mm.yyyy"
})

This fixed it for me.

这为我修好了。

回答by Yishai Landau

For me, the issue was that the method was called twice. Make sure that it's called only once, and you won't have this error

对我来说,问题是该方法被调用了两次。确保它只被调用一次,你不会有这个错误

回答by Rafael Pereira

For me resolved add input to select $('input.datepicker') because i had another element on the code that had datepicker as class too.

对我来说,解决了添加输入以选择 $('input.datepicker') 因为我在代码中还有另一个元素,它也将 datepicker 作为类。