向网站添加jquery时间选择器

向网站添加jquery时间选择器,jquery,Jquery,我正在尝试添加将jquery添加到应用程序中的功能。我已经试着遵循这一点。 我将脚本附加到我的网站中,并将jquery站点中提到的example2的div放在了中。但是我的网站仍然没有显示jquery Timepicker示例2。我将非常感谢你的帮助。谢谢 编辑: 我已经添加了代码,但仍然不起作用。下面是script.js: $(document).ready(function(){ /* The following code is executed once the DOM is lo

我正在尝试添加将jquery添加到应用程序中的功能。我已经试着遵循这一点。 我将脚本附加到我的网站中,并将jquery站点中提到的example2的div放在了中。但是我的网站仍然没有显示jquery Timepicker示例2。我将非常感谢你的帮助。谢谢

编辑: 我已经添加了代码,但仍然不起作用。下面是
script.js

$(document).ready(function(){
    /* The following code is executed once the DOM is loaded */

    $(".todoList").sortable({
        axis        : 'y',              // Only vertical movements allowed
        containment : 'window',         // Constrained by the window
        update      : function(){       // The function is called after the todos are rearranged

            // The toArray method returns an array with the ids of the todos
            var arr = $(".todoList").sortable('toArray');


            // Striping the todo- prefix of the ids:

            arr = $.map(arr,function(val,key){
                return val.replace('todo-','');
            });

            // Saving with AJAX
            $.get('ajax.php',{action:'rearrange',positions:arr});
        },

        /* Opera fix: */

        stop: function(e,ui) {
            ui.item.css({'top':'0','left':'0'});
        }
    });

    // A global variable, holding a jQuery object 
    // containing the current todo item:

    var currentTODO;

    // Configuring the delete confirmation dialog
    $("#dialog-confirm").dialog({
        resizable: false,
        height:130,
        modal: true,
        autoOpen:false,
        buttons: {
            'Delete item': function() {

                $.get("ajax.php",{"action":"delete","id":currentTODO.data('id')},function(msg){
                    currentTODO.fadeOut('fast');
                })

                $(this).dialog('close');
            },
            Cancel: function() {
                $(this).dialog('close');
            }
        }
    });

    // When a double click occurs, just simulate a click on the edit button:
    $('.todo').live('dblclick',function(){
        $(this).find('a.edit').click();
    });

    // If any link in the todo is clicked, assign
    // the todo item to the currentTODO variable for later use.

    $('.todo a').live('click',function(e){

        currentTODO = $(this).closest('.todo');
        currentTODO.data('id',currentTODO.attr('id').replace('todo-',''));

        e.preventDefault();
    });

    // Listening for a click on a delete button:

    $('.todo a.delete').live('click',function(){
        $("#dialog-confirm").dialog('open');
    });

    // Listening for a click on a edit button

    $('.todo a.edit').live('click',function(){

        var container = currentTODO.find('.text');

        if(!currentTODO.data('origText'))
        {
            // Saving the current value of the ToDo so we can
            // restore it later if the user discards the changes:

            currentTODO.data('origText',container.text());
        }
        else
        {
            // This will block the edit button if the edit box is already open:
            return false;
        }

        $('<input type="text">').val(container.text()).appendTo(container.empty());

        // Appending the save and cancel links:
        container.append(
            '<div class="editTodo">'+
                '<a class="saveChanges" href="#">Save</a> or <a class="discardChanges" href="#">Cancel</a>'+
            '</div>'
        );

    });

    // The cancel edit link:

    $('.todo a.discardChanges').live('click',function(){
        currentTODO.find('.text')
                    .text(currentTODO.data('origText'))
                    .end()
                    .removeData('origText');
    });

    // The save changes link:

    $('.todo a.saveChanges').live('click',function(){
        var text = currentTODO.find("input[type=text]").val();

        $.get("ajax.php",{'action':'edit','id':currentTODO.data('id'),'text':text});

        currentTODO.removeData('origText')
                    .find(".text")
                    .text(text);
    });


    // The Add New ToDo button:

    var timestamp=0;
    $('#addButton').click(function(e){

        // Only one todo per 5 seconds is allowed:
        if((new Date()).getTime() - timestamp<5000) return false;

        $.get("ajax.php",{'action':'new','text':'New Todo Item. Doubleclick to Edit.','rand':Math.random()},function(msg){

            // Appending the new todo and fading it into view:
            $(msg).hide().appendTo('.todoList').fadeIn();
        });

        // Updating the timestamp:
        timestamp = (new Date()).getTime();

        e.preventDefault();
    });

    //for box that asks for date and time
    $('#example2').datetimepicker({
    ampm: true
});
}); // Closing $(document).ready()
$(文档).ready(函数(){
/*加载DOM后,将执行以下代码*/
$(“.todoList”)。可排序({
轴:“y”//仅允许垂直移动
包含:'窗口',//受窗口约束
update:function(){//重新排列TODO后调用该函数
//toArray方法返回一个包含TODO ID的数组
var arr=$(“.todoList”).sortable('toArray');
//将ID的todo前缀分条:
arr=$.map(arr,函数(val,键){
返回值替换('todo-','');
});
//使用AJAX保存
$.get('ajax.php',{action:'reareat',positions:arr});
},
/*Opera修复:*/
停止:功能(e、ui){
css({'top':'0','left':'0'});
}
});
//包含jQuery对象的全局变量
//包含当前待办事项的项目:
var currentTODO;
//配置删除确认对话框
$(“#对话框确认”)。对话框({
可调整大小:false,
身高:130,
莫代尔:是的,
自动打开:错误,
按钮:{
“删除项”:函数(){
$.get(“ajax.php”,{“action”:“delete”,“id”:currentTODO.data('id')},函数(msg){
电流衰减(快速);
})
$(this.dialog('close');
},
取消:函数(){
$(this.dialog('close');
}
}
});
//双击时,只需模拟单击编辑按钮:
$('.todo').live('dblclick',function()){
$(this)。查找('a.edit')。单击();
});
//如果单击了todo中的任何链接,请指定
//将todo项添加到currentTODO变量以供以后使用。
$('.todo a').live('click',函数(e){
currentTODO=$(this).closest('.todo');
currentTODO.data('id',currentTODO.attr('id')。replace('todo-','');
e、 预防默认值();
});
//正在侦听对删除按钮的单击:
$('.todo a.delete').live('单击',函数()){
$(“#对话框确认”)。对话框(“打开”);
});
//正在侦听对编辑按钮的单击
$('.todo a.edit').live('单击',函数()){
var container=currentTODO.find('.text');
如果(!currentTODO.data('origText'))
{
//保存ToDo的当前值,以便
//如果用户放弃更改,请稍后恢复:
currentTODO.data('origText',container.text());
}
其他的
{
//如果编辑框已打开,这将阻止编辑按钮:
返回false;
}
$('').val(container.text()).appendTo(container.empty());
//附加“保存”和“取消”链接:
container.append(
''+
“或者”+
''
);
});
//取消编辑链接:
$('.todo a.discardChanges').live('单击',函数()){
currentTODO.find('.text')
.text(currentTODO.data('origText'))
(完)
.removeData(“原始文本”);
});
//保存更改链接:
$('.todo a.saveChanges').live('单击',函数()){
var text=currentTODO.find(“输入[type=text]”).val();
$.get(“ajax.php”,{'action':'edit','id':currentTODO.data('id'),'text':text});
currentTODO.removeData('origText')
.find(“.text”)
.文本(文本);
});
//“添加新ToDo”按钮:
var时间戳=0;
$(“#添加按钮”)。单击(函数(e){
//每5秒只允许一次todo:

if((new Date()).getTime()-timestamp我看不到您在任何地方向输入字段添加了日期选择器或时间选择器

你需要说

$('#example2').timepicker({});


根据您在文档中的需要,脚本已准备好将功能绑定到输入字段。

将其放入HTML文件:

<script language="javascript"> 
$(function() {
    $('#example2').timepicker();
});
</script> 

$(函数(){
$(“#示例2”).timepicker();
});

将类“hasDatepicker”硬编码到输入文本字段中。从代码中删除该类,因为jQueryUI认为该函数已经执行。jQuery UI在将datetimepicker函数应用到元素后添加该类

这使得jQUi不会重复同样的工作,也不会直接跳转到选项修改

你有:

<input id="example2" class="hasDatepicker" type="text" value="" name="example2">

这样做:

<input id="example2" type="text" value="" name="example2">

jQuery UI执行以下操作:

<input id="example2" class="hasDatepicker" type="text" value="" name="example2">


查看指向实际测试页面的链接,源HTML标记显示您的输入上有属性
class=“hasDatepicker”
。请删除此属性。它会使日期选择器初始化代码短路,并阻止小部件正确连接。

您是否这样做:$(“#示例1”).datetimepicker();你能发布更多的代码吗?是的,请发布你试图使用的所有javascript和html代码。@Alytrem:不。jquery文件不应该有这些代码吗?是的,你应该有。请看我下面的回答!我已经在头部添加了它,但没有更改。我必须在正文中添加它吗?你可以,但在jquery导入之后再添加它。啊,好的。我会的ally在关闭body标签之前放置了导入脚本。之后我会添加它。谢谢。我已经在头部添加了它,但没有更改。我必须在正文中添加它吗?我在你的网站上看到script.js。在文档中添加这一行。readyI按照你说的添加,但仍然不起作用。我
<input id="example2" class="hasDatepicker" type="text" value="" name="example2">