代码之家  ›  专栏  ›  技术社区  ›  ilija veselica

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

  •  0
  • ilija veselica  · 技术社区  · 14 年前

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

    $(".pick_date").AnyTime_picker({ format: "%W, %M %D, %z" });
    

    这是在任何时候初始化选取器的代码 .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>
    
    2 回复  |  直到 13 年前
        1
  •  2
  •   Krunal    14 年前

    这很管用。

    <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的示例页面中尝试了这个插件。它起作用了。

    我想你应该检查一下房间 html data

    $(".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>
    
        2
  •  0
  •   Chuck Norris Rohidas Kadam    12 年前

    $.AnyTime_picker() 应该在类和附加元素上工作。请张贴在这里的网址,我可以调试的问题,或给我一个消息通过 http://www.ama3.com/doorkeeper/ 我会把你的电子邮件地址列在白名单上,这样你就可以把相关的HTML/CSS/JS文件发邮件给我,我就可以在我的电脑上重现这个问题。谢谢!