将内联 jquery datepicker 与输入字段结合起来?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19344135/
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-08-26 23:43:24  来源:igfitidea点击:

Combine inline jquery datepicker with an input field?

javascriptjquerydatepicker

提问by Hyman

I know that I can use $('div').datepicker()to get an inline datepicker, but how do I show the datepickerfixed inline underneath its input field?

我知道我可以$('div').datepicker()用来获取内联日期选择器,但是如何datepicker在其输入字段下方显示固定内联?

The altfield option does not work for me because I want the datepickerto also react on a date entered into the input field.

alt,因为我想现场选项不为我工作datepicker也对输入到输入域的日期作出反应。

I would need something like the following pseudocode:

我需要类似以下伪代码的东西:

<inputfield type="text" id="d" >
<div id="z"></div>  
<script> $('#z').datepicker().bindToInputfield($('#d')) </script>

回答by Tats_innit

Try this: Working demohttp://jsfiddle.net/KRFCH/

试试这个:工作演示http://jsfiddle.net/KRFCH/

The altFieldoption will link to the second field you want! http://jqueryui.com/datepicker/#alt-field

altField选项将链接到您想要的第二个字段!http://jqueryui.com/datepicker/#alt-field

Now note: any change in the input will reflect in the datepicker on change

现在注意:输入中的任何更改都将反映在日期选择器上 change

This should fit your cause :)

这应该适合你的原因 :)

Code

代码

$('#z').datepicker({
    inline: true,
    altField: '#d'
});

$('#d').change(function(){
    $('#z').datepicker('setDate', $(this).val());
});

回答by Aditya Vikas Devarapalli

It's not possible to get the datepickerinline just by using the inputfield . You need to use a divalong with an inputto get what you want.

datepicker仅使用inputfield 是不可能获得内联的。你需要使用 adiv和 aninput来获得你想要的。

NOTE:Any changes made in the inputwill reflect in the datepicker

注意:在 中所做的任何更改都input将反映在datepicker

Example Code

示例代码

<input type="text" id="text" />
<div id="mydiv"></div>
<script>
$('#mydiv').datepicker();

$('#text').change(function(){
    $('#mydiv').datepicker('setDate', $(this).val());
});
$('#mydiv').change(function(){
    $('#text').attr('value',$(this).val());
});
</script>

Check out this jsfiddle I've created for you: http://jsfiddle.net/v9XCP/

查看我为您创建的这个 jsfiddle:http: //jsfiddle.net/v9XCP/