jQuery - 附加元素上 AnyTime Picker 的实时初始化
$(".pick_date").AnyTime_picker({ format: "%W, %M %D, %z" });
这是在 < 上初始化 AnyTime 选择器的代码code>.pick_date 元素。但如果我追加元素,那么 AnyTime 就不起作用。有没有办法让它发挥作用。
我尝试过这个:
$('#submit-buton').live("click", function() {
$.ajax({
type: "POST",
url: '/AddTask',
dataType: 'html',
success: function(data) {
$("#taskModule").append(data);
$(".pick_date").AnyTime_picker({ format: "%W, %M %D, %z" });
}
});
});
但没有效果......
有什么想法吗?
编辑:
这有效:
<div id="mydatepicker">
</div>
<input type="button" id="MyButton" value="Append" />
<script type="text/javascript">
$(function() {
var mydatepickerHtml = 'English: <input type="text" id="field1" size="50" value="Sunday, July 30th in the Year 1967 CE" /><br/>Español: <input type="text" id="field2" value="12:34" />';
$("#mydatepicker").append(mydatepickerHtml);
$('#MyButton').live("click", function() {
// ...
});
AnyTime.picker( "field1", { format: "%W, %M %D in the Year %z %E", firstDOW: 1 } );
$("#field2").AnyTime_picker(
{ format: "%H:%i", labelTitle: "Hora",
labelHour: "Hora", labelMinute: "Minuto" } );
});
</script>
但这并不......
<div id="mydatepicker">
</div>
<input type="button" id="MyButton" value="Append" />
<script type="text/javascript">
$(function() {
$('#MyButton').live("click", function() {
var mydatepickerHtml = 'English: <input type="text" id="field1" size="50" value="Sunday, July 30th in the Year 1967 CE" /><br/>Español: <input type="text" id="field2" value="12:34" />';
$("#mydatepicker").append(mydatepickerHtml);
});
AnyTime.picker( "field1", { format: "%W, %M %D in the Year %z %E", firstDOW: 1 } );
$("#field2").AnyTime_picker(
{ format: "%H:%i", labelTitle: "Hora",
labelHour: "Hora", labelMinute: "Minuto" } );
});
</script>
$(".pick_date").AnyTime_picker({ format: "%W, %M %D, %z" });
This is code to initialize AnyTime picker on .pick_date
element. But if I append element then AnyTime doesn't work on it. Is there a way to make it work.
I tried this:
$('#submit-buton').live("click", function() {
$.ajax({
type: "POST",
url: '/AddTask',
dataType: 'html',
success: function(data) {
$("#taskModule").append(data);
$(".pick_date").AnyTime_picker({ format: "%W, %M %D, %z" });
}
});
});
But no effect...
Any idea?
EDIT:
This works:
<div id="mydatepicker">
</div>
<input type="button" id="MyButton" value="Append" />
<script type="text/javascript">
$(function() {
var mydatepickerHtml = 'English: <input type="text" id="field1" size="50" value="Sunday, July 30th in the Year 1967 CE" /><br/>Español: <input type="text" id="field2" value="12:34" />';
$("#mydatepicker").append(mydatepickerHtml);
$('#MyButton').live("click", function() {
// ...
});
AnyTime.picker( "field1", { format: "%W, %M %D in the Year %z %E", firstDOW: 1 } );
$("#field2").AnyTime_picker(
{ format: "%H:%i", labelTitle: "Hora",
labelHour: "Hora", labelMinute: "Minuto" } );
});
</script>
But this doesn't...
<div id="mydatepicker">
</div>
<input type="button" id="MyButton" value="Append" />
<script type="text/javascript">
$(function() {
$('#MyButton').live("click", function() {
var mydatepickerHtml = 'English: <input type="text" id="field1" size="50" value="Sunday, July 30th in the Year 1967 CE" /><br/>Español: <input type="text" id="field2" value="12:34" />';
$("#mydatepicker").append(mydatepickerHtml);
});
AnyTime.picker( "field1", { format: "%W, %M %D in the Year %z %E", firstDOW: 1 } );
$("#field2").AnyTime_picker(
{ format: "%H:%i", labelTitle: "Hora",
labelHour: "Hora", labelMinute: "Minuto" } );
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
这有效。
我在附加 html 的示例页面中尝试了这个插件。有用。
我认为你应该检查ajax请求返回的
html数据
。它包含 pick_date 元素吗?您还可以检查
$(".pick_date").length
以验证您是否正在获取元素。看看我的样品。
EDIT:
This works.
I tried out this plugin in sample page on appended html. It works.
I think you should check the
html data
returned on ajax request. Does it contain pick_date element?You can also check the
$(".pick_date").length
to verify that you are getting element.Checkout my sample.
$.AnyTime_picker()
应该适用于类以及附加元素。请在此处发布 URL,我可以在其中调试问题,或通过 http://www.ama3 向我发送消息.com/doorkeeper/,我会将您的电子邮件地址列入白名单,以便您可以通过电子邮件向我发送相关的 HTML/CSS/JS 文件,我可以尝试在我的计算机上重现该问题。谢谢!$.AnyTime_picker()
should work on classes as well as appended elements. Please post the URL here where I can debug the problem, or send me a message via http://www.ama3.com/doorkeeper/ and I will whitelist your email address, so you can email me the relevant HTML/CSS/JS files and I can attempt to reproduce the problem on my computer. Thanks!