简体   繁体   English

如何将日期选择器插入到 jquery 向导中?

[英]how to insert datepicker into a jquery wizard?

I have created a jquery wizard form, and inside i have to insert an input -> datepicker, but it doesn't work.我创建了一个 jquery 向导表单,在里面我必须插入一个输入 -> 日期选择器,但它不起作用。

Here is the input line:这是输入行:

<label for="created">Creation date *</label><input name="created" id="created" type="text">

and here the simple javascript:这里是简单的javascript:

<script>
$('#created').datepicker();
</script>

I think the problem is due to the wizard that is rendered after that the JavaScript is loaded.我认为问题是由于在加载 JavaScript 之后呈现的向导。 Anyway, I still searching for a solution.无论如何,我仍在寻找解决方案。

Can anyone help me?谁能帮我?

Thanks Gaetano谢谢加埃塔诺

Depending in where your code is placed in the page, the DOM is not ready yet (so the $('#created') selector does not return a match).根据您的代码在页面中的位置,DOM 尚未准备好(因此$('#created')选择器不会返回匹配项)。

Add a DOM ready handler around your code:在代码周围添加一个 DOM 就绪处理程序:

<script>
    $(function(){
        $('#created').datepicker();
    });
</script>

Note: $(function(){yourcode});注意: $(function(){yourcode}); is a shortcut for $(document).ready(function(){yourcode});$(document).ready(function(){yourcode});的快捷方式$(document).ready(function(){yourcode});

Use jquery ready function to initialize datepicker.使用 jquery 就绪函数来初始化日期选择器。

for example:例如:

<script>
    $(document).ready(function(){
    $('#created').datepicker();
});
</script>

I found a solution.我找到了解决方案。 Just 12 days ago were released new features that allow you to initialize variables (or anything that might serve) and fires these ones when the wizard is initialized.就在 12 天前发布了一些新功能,允许您初始化变量(或任何可能提供的东西)并在初始化向导时触发这些变量。

In my case I used the onInit() for event management.就我而言,我使用 onInit() 进行事件管理。

At this link is possible to see all the specifications for the jQuery wizard-step.在此链接中可以查看 jQuery 向导步骤的所有规范。

Byez Gaetano比耶斯·加埃塔诺

I tried to set我试图设置

onInit : function (event, currentIndex) { $(".datepicker").datepicker(); },

still doesn't work (while it works outside the wizard div)仍然不起作用(虽然它在向导 div 之外工作)

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

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