jQuery 移动 ->覆盖 jQuery UI 日期选择器 ->布局损坏
我在我的 Web 应用程序中使用 jQuery Mobile。有一个日期选择器会覆盖默认的 jQuery UI 日期选择器。
这是来源: https://github.com/jquery/jquery-mobile/tree /master/experiments/ui-datepicker
覆盖它的 JavaScript 文件位于此处: https://github .com/jquery/jquery-mobile/blob/master/experiments/ui-datepicker/jquery.ui.datepicker.mobile.js
我有这行代码:
$(".ui-page").live("pagecreate", function(){
$("input[type='date'], input[data-type='date']").each(function(){
$(this).after($("<div />").datepicker({ altField: "#" + $(this).attr("id"), showOtherMonths: true }));
});
});
在这种情况下,我得到一个日期选择器,它总是可见的。要仅在用户单击日期文本字段时具有可见性,日期选择器必须连接到输入字段,但此处情况并非如此。 所以我必须删除 .after("
")
。但是,日期选择器的设计完全被破坏了,似乎日期选择器的重写没有生效,因为没有应用CSS样式。那么,这里出了什么问题呢?
预先感谢您&此致。
I am using jQuery Mobile in my web application. There is a datepicker which overrides the default jQuery UI datepicker.
Here is the source:
https://github.com/jquery/jquery-mobile/tree/master/experiments/ui-datepicker
The JavaScript file which overrides it, is here:
https://github.com/jquery/jquery-mobile/blob/master/experiments/ui-datepicker/jquery.ui.datepicker.mobile.js
I have this line of code:
$(".ui-page").live("pagecreate", function(){
$("input[type='date'], input[data-type='date']").each(function(){
$(this).after($("<div />").datepicker({ altField: "#" + $(this).attr("id"), showOtherMonths: true }));
});
});
In this case, I get a datepicker which is always visible. To have the visibility only if a user clicks into a date text field, the datepicker must be connected to the input field, which is here not the case.
So I have to delete the .after("<div />")
. But then, the design of the datepicker is totally broken, it seems that the rewrite of the datepicker does not take effect, because the CSS styles are not applied.
So, what's wrong here?
Thank you in advance & Best Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是我的解决方案
This was my solution
要解决日历问题,您只需更改 Squish 代码中的选择器
示例
在对话框中创建此内容是也很简单,只需将其放在另一个 html 中并像这样调用它
Dialog文档
To fix the calendar problem you just need to change a selector in Squish's code
Example Here
Creating this in a dialog is simple too, just put it in another html and call it like so
Dialog Documentation
你是对的,我为第一次没有正确实施而道歉。
这应该可以解决您的问题:
它将在加载时隐藏您的日历,当输入处于焦点(单击或选项卡到)时显示它,并在选择日期后立即再次隐藏它(但不会干扰切换月份)。
这是实时示例
You were correct, I apologize for not properly implementing it the first time.
This should fix your issue:
It will hide your calendar on load, show it when the input is in focus (clicked on or tabbed to) and hide it again as soon as a date is selected (but will not interfere with switching months).
Here is the example live
我在同一页面中使用两个日期选择器也遇到了同样的问题。这是我的解决方案:
HTML 代码:
内。有一个动态创建的新 DIV,其 id="dp1298574069963"。我将其捕获在变量 (
var idDivStart = $("#startPicker div").attr("id");
) 中,并使用它的变量来指定该 Div 中具有 ui 的所有元素-datepicker 类将会显示 ($("#"+idDivStart+" .ui-datepicker").show();
)。JS代码:
希望对你有帮助。
I had the same issue with two datepickers in the same page. This was my solution:
HTML code:
<div data-role="fieldcontain" ...>
. there is a new DIV that was created dinamically and has this id="dp1298574069963". I captured it in a variable (var idDivStart = $("#startPicker div").attr("id");
) and use it variable to specify that all elements inside that Div that has the ui-datepicker class will be shown ($("#"+idDivStart+" .ui-datepicker").show();
).JS code:
I hope to help you.
移动日期选择器的作者有一个功能示例 在他的 git 页面上。
它隐藏了日期选择器并按预期显示一个输入框。您的实施与标准之间到底有什么区别?你能给出你正在做的事情的工作片段吗?如果您觉得更容易,可以在 JSBin 上对其进行标记。
The author of mobile datepicker has a functioning example on his git page.
It hides the datepicker and displays an input box as intended. What exactly is the difference between your implementation and the standard? Can you give a working snippet of what you're doing? You can mark it up on JSBin if you feel that'll be easier.
我在处理两个日期时遇到了类似的问题,这有效:
标记(C# MVC3):
脚本:
I had a similar problem working with two dates and this worked:
Markup (C# MVC3):
Script: