将内联 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
Combine inline jquery datepicker with an input field?
提问by Hyman
I know that I can use $('div').datepicker()
to get an inline datepicker, but how do I show the datepicker
fixed inline underneath its input field?
我知道我可以$('div').datepicker()
用来获取内联日期选择器,但是如何datepicker
在其输入字段下方显示固定内联?
The alt
field option does not work for me because I want the datepicker
to 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 altField
option 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 datepicker
inline just by using the input
field . You need to use a div
along with an input
to get what you want.
datepicker
仅使用input
field 是不可能获得内联的。你需要使用 adiv
和 aninput
来获得你想要的。
NOTE:Any changes made in the input
will 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/