jQuery - 附加元素上 AnyTime Picker 的实时初始化

发布于 2024-09-07 09:33:11 字数 2364 浏览 3 评论 0原文

http://www.ama3.com/anytime/

$(".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>

http://www.ama3.com/anytime/

$(".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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七七 2024-09-14 09:33:11

编辑:

这有效。

<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> 

我在附加 html 的示例页面中尝试了这个插件。有用。

我认为你应该检查ajax请求返回的html数据。它包含 pick_date 元素吗?

您还可以检查 $(".pick_date").length 以验证您是否正在获取元素。

看看我的样品。

<html>
<head>

<link rel="stylesheet" type="text/css" href="anytimec.css" />
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script>                        
<script type="text/javascript" src="anytimec.js"></script>

</head>
<body>
<div id="mydatepicker">
</div>

<script type="text/javascript">

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" />';

$(function()
{
$("#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>
</body>
</html>

EDIT:

This works.

<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> 

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.

<html>
<head>

<link rel="stylesheet" type="text/css" href="anytimec.css" />
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script>                        
<script type="text/javascript" src="anytimec.js"></script>

</head>
<body>
<div id="mydatepicker">
</div>

<script type="text/javascript">

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" />';

$(function()
{
$("#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>
</body>
</html>
爱她像谁 2024-09-14 09:33:11

$.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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文