简体   繁体   English

多个JavaScript日期选择器

[英]multiple javascript date picker

I am building and web page in php and all the content is laid out like so .. 我正在用php构建网页,所有内容都是这样布置的..

<div>
<form>
<input type='text' id='datepick' />
</form>
</div>

<div>
<form>
<input type='text' id='datepick' />
</form>
</div>

<div>
<form>
<input type='text' id='datepick' />
</form>
</div>

Its layout is a bit more complex really but basically the problem I am having is that the datepick id calls the datpick function but it only works on the first input and ignores the rest. 它的布局确实有点复杂,但是基本上我遇到的问题是datepick id调用datpick函数,但它仅在第一个输入上起作用,而忽略其余输入。 I cant give them there own ids all the inputs must be called the same. 我不能给他们自己的ID,所有输入都必须称为相同。

This is the function 这是功能

<script type="text/javascript">

        new datepickr('datepick', {
            'dateFormat': 'd-m-Y'
        });
</script>

Can any one tell me how to make the datepick work on all input fields. 谁能告诉我如何使datepick在所有输入字段上起作用。

Thanks in advance, I am proper struggling with this one .... 在此先感谢,我正为此奋斗....

Look at the example here on how to use it: 在这里查看有关如何使用它的示例:

http://www.joshsalverda.com/sandbox/date_pick/datepickr.html (from https://code.google.com/p/datepickr/ ) http://www.joshsalverda.com/sandbox/date_pick/datepickr.html (来自https://code.google.com/p/datepickr/

You must give them all their own id. 必须给他们所有自己的ID。

HTML spec requires id to be unique but it will still render the page for you. HTML规范要求id是唯一的,但它仍将为您呈现页面。 Which element will be found when you look for a non-unique id in undefined. 当您在undefined中查找非唯一ID时,将找到哪个元素。 It might be the first, it might be the last, you might get an error. 它可能是第一个,也可能是最后一个,您可能会遇到错误。

or just change the id to class like mentioned: 或者只是将id更改为上面提到的类:

<script>    $(function() {
        $( ".datepicker" ).datepicker();
      });
</script>

<p>Date: <input type="text" class="datepicker" /></p>
<p>Date: <input type="text" class="datepicker" /></p>
<p>Date: <input type="text" class="datepicker" /></p>

works fine. 工作正常。

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

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