小编Luk*_*uha的帖子

未捕获的TypeError:无法读取undefined - bootstrap datepicker的属性'split'

我在bootstrap模式窗口中使用bootstrap datepicker作为输入.当我第一次打开这个窗口时,一切正常,而且datepicker工作正常.当我关闭这个模态窗口并再次打开它时,我的js控制台说Uncaught TypeError: Cannot read property 'split' of undefined

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

这是我的模态窗口:

<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>
Run Code Online (Sandbox Code Playgroud)

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

$('.datepicker').datepicker({
           format: "dd.mm.yyyy"
})
Run Code Online (Sandbox Code Playgroud)

这是我的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 jiný termín:</label></strong></p>
    <p style="float: left"><input type="text" class="datepicker text" name="otherDate" …
Run Code Online (Sandbox Code Playgroud)

jquery datepicker twitter-bootstrap

8
推荐指数
1
解决办法
2万
查看次数

无法读取未定义的属性'indexOf'

我正在尝试在jquery中为几个日期选择器设置不同的选项.我的代码看起来像这样:

{foreach $cart->getItems() as $item}
    {if $item->action->prereservation}
        var disableDates = new Array();
        {if $item->action->hasVariants()}
        disableDates[{!$item->id}] = {$disabledDates[$item->action->id][$item->idVariant]};
        {else}
        disableDates[{!$item->id}] = {$disabledDates[$item->action->id]};
        {/if}

        if (disableDates[{!$item->id}].length !== 0) {
            $(".datepicker_"+'{$item->id}').datepicker({
                maxDate: new Date('{!$item->action->voucherTo|date: Y-m-d}'),
                beforeShowDay: function(date){
                    var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                    console.log(disableDates[{!$item->id}]) // result is undefined (but not for last iteration)
                    return [ disableDates[{!$item->id}].indexOf(string) == -1 ]
                }
            })
        } else {
            $(".datepicker_"+'{$item->id}').datepicker({
                maxDate: new Date('{!$item->action->voucherTo|date: Y-m-d}'),
            })
        }
    {/if}
{/foreach}
Run Code Online (Sandbox Code Playgroud)

但如果foreach中有多个项目,我的js控制台显示错误无法读取第一次迭代的未定义属性'indexOf',只有最后一次是好的.有人能帮帮我吗?

在我的代码我结合模板系统Latte和jquery.

这是我在浏览器中的最终代码:

var disableDates = new Array();
        disableDates[777955] = ["2014-07-25","2014-07-26","2014-07-27","2014-07-28","2014-07-29","2014-07-30","2014-07-31"]; …
Run Code Online (Sandbox Code Playgroud)

javascript jquery nette

6
推荐指数
1
解决办法
6万
查看次数