简体   繁体   English

在HTML页面上实现Framework7日历

[英]Implement Framework7 calendar on html page

I'm trying to add framework7 calendar on HTML-page, but it doesn't show up. 我正在尝试在HTML页上添加framework7日历,但没有显示。 What can be the problem? 可能是什么问题?

My html-code: 我的html代码:

  <div class="content-block-title">Default setup</div>
    <div class="list-block">
        <ul>
            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-input">
                            <input type="text" placeholder="Your birth date" readonly id="calendar-default" />
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>          

My js-code 我的js代码

var myApp = new Framework7();
var calendarDefault = myApp.calendar({
input: '#calendar-default',
});

The problem may be that the DOM is not ready yet, in particular the '#calendar-default' input element. 问题可能是DOM尚未准备好,尤其是'#calendar-default'输入元素。 You can check if that's the problem using this line just before you initialize the calendar: 您可以在初始化日历之前使用此行检查这是否是问题:

console.log(document.getElementById('calendar-default'));

If it prints 'null' than that's your problem. 如果它显示“ null”,那是您的问题。

The solution depends on your context. 解决方案取决于您的上下文。 You can solve it by using Dom7 (part of Framework7) and listening to the DOMContentLoaded event: 您可以通过使用Dom7 (Framework7的一部分)并侦听DOMContentLoaded事件来解决此问题:

$$(document).on('DOMContentLoaded', function() {
    var calendarDefault = myApp.calendar({
        input: '#calendar-default',
    });
});

If you're using it with custom elements or some sort of client side MV-* framework the initialization logic may need to go in some life-cycle-method (I'm using Aurelia and had this problem when tried to create a datepicker custom component ). 如果您将其与自定义元素或某种客户端MV- *框架一起使用,则初始化逻辑可能需要采用某种生命周期方法(我正在使用Aurelia ,并在尝试创建日期选择器自定义项时遇到了此问题组件 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM