Javascript JQuery Datepicker中的onSelect事件不';我好像没开枪

Javascript JQuery Datepicker中的onSelect事件不';我好像没开枪,javascript,jquery,datepicker,Javascript,Jquery,Datepicker,这可能只是一个简单的错误,但我花了3个小时试图解决它——但没有成功 我最终想做的是使用输入的日期,并将其与截止日期进行比较,以说明提交是否太晚。不过,为了简化起见,我现在只想告诉我,日期已经改变,但没有成功。我哪里出了问题 $("#id_submission_date").datepicker({ onSelect: function(dateText) { $("#late_submission_warning").text("Date selected");

这可能只是一个简单的错误,但我花了3个小时试图解决它——但没有成功

我最终想做的是使用输入的日期,并将其与截止日期进行比较,以说明提交是否太晚。不过,为了简化起见,我现在只想告诉我,日期已经改变,但没有成功。我哪里出了问题

$("#id_submission_date").datepicker({
    onSelect: function(dateText) {
        $("#late_submission_warning").text("Date selected");
    }
 });
以下是页面中的(缩短的)HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>  Feedback for Student, Test</title>
    <meta name="description" content="">
    <link href="/static/css/bootstrap.css" rel="stylesheet" media="screen">
    <link href="/static/css/jquery.qtip.min.css" rel="stylesheet">
    <style type="text/css">
        body {
            padding-top: 60px;
            padding-bottom: 40px;
        }
        .sidebar-nav{
            padding: 9px 0;
        }
    </style>
</head>

<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
...
</nav>

<form action="" method="post" accept-charset="utf-8" role="form">
<input type='hidden' name='csrfmiddlewaretoken' value='...' />

<div class="container">

    <h1>European Law (2013/2014): Essay</h1>
    <h2>Test Student</h2>
     ...

    <label for="submission_date">Submission Date</label>
    <input class="form-control" data-date-format="dd/mm/yyyy" id="id_submission_date" name="submission_date" type="text" value="13/04/2015" />

    <select class="form-control" id="id_category_mark_2" name="category_mark_2">
    <option value="" selected="selected">---------</option>
        <option value="39">0 - 39 %</option>
        <option value="49">40 - 49 %</option>
        <option value="59">50 - 59 %</option>
        <option value="69">60 - 69 %</option>
        <option value="79">70 - 79 %</option>
        <option value="80">80 or more</option>
    </select>

    <div id="late_submission_warning"></div>

    <h4>General Comments</h4>
    <textarea class="form-control" cols="40" id="id_comments" name="comments" rows="10">
    </textarea>
    <br><br>
    <input type = "submit" value="Save" class="btn btn-default">
    </form>
</div>

<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.js"></script>
<script src="/static/js/bootstrap-datepicker.js"></script>
<script src="/static/js/jquery.tablesorter.js"></script>
<script src="/static/js/jquery.metadata.js"></script>
<script src="/static/js/jquery.validate.min.js"></script>
<script src="/static/js/bootbox.min.js"></script>
<script src="/static/js/jquery.qtip.min.js"></script>

<script type="text/javascript">

$(document).ready(function() 
    { 
    $("#sortable_table").tablesorter({
        sortList: [[0,0],[1,0]]
        }); 
    } 
); 

</script>

<script type="text/javascript">
$(document).ready(function(){

    $("#id_submission_date").datepicker({
        onSelect: function(dateText) {
            console.log(dateText);
        }
    });

    $("#category_2").qtip({
        content: {
            text: '80+ very full and perceptive awareness of issues, with original critical and analytical assessment of the issues and an excellent grasp of their wider significance.<br />70+ full and perceptive awareness of issues and a clear grasp of their wider significance.<br />60 - 69 adequate awareness of issues and a serious understanding of their wider significance.<br />50 - 59 some awareness of issues and their wider significance.<br />40 - 49 limited awareness of issues and their wider significance.<br />Below 40 very limited awareness of issues and of their wider significance.'
            }
        });
    });

</script>

</body>
</html>

对学生、考试的反馈
身体{
填充顶部:60px;
填充底部:40px;
}
.侧边栏导航{
填充:9px0;
}
...
欧洲法律(2013/2014):论文
测试生
...
提交日期
---------
0 - 39 %
40 - 49 %
50 - 59 %
60 - 69 %
70 - 79 %
80或以上
一般性意见


$(文档).ready(函数() { $(“#可排序表”).tablesorter({ 排序列表:[[0,0],[1,0]] }); } ); $(文档).ready(函数(){ $(“#id#U提交日期”).datepicker({ onSelect:函数(日期文本){ console.log(dateText); } }); $(“类别2”).qtip({ 内容:{ 正文:“80+对问题有充分和敏锐的认识,对问题有独到的批判性和分析性评估,对其更广泛的意义有极好的把握。
70+对问题有充分和敏锐的认识,对其更广泛的意义有清晰的把握。
60-69对问题有充分的认识,并认真理解其重要性重要性。
50-59对一些问题及其更广泛意义的认识。
40-49对问题及其更广泛意义的认识有限。
40岁以下对问题及其更广泛意义的认识非常有限。
} }); });
您的JavaScript似乎有问题,您必须查看控制台消息,才能了解出了什么问题

无论如何,我希望在做任何评论或完整的解决方案之前看到完整的HTML和代码。但根据您的要求,保持事情简单,并确保正确捕获更改的日期,我们必须遵循以下方法

     $("#id_submission_date").datepicker({
        onSelect: function(dateText) {
         console.log(dateText);
        }
     });
此处的“dateText”应包含所需的选定日期。检查您的浏览器控制台。但是,如果出现错误,将显示正确的错误

一旦获得了合适的日期,您就可以进行比较。


如果出现错误,请在此处发布错误消息,我们可以进行更多讨论。

请同时发布html。我使用了您指定的代码,但控制台中没有显示任何内容-Chromium和Firebug中都没有。我可以发布完整的HTML代码,但这是一个Django页面,而且相当长和复杂。其他一切都很好,所以我认为错误一定在于新代码。如果console.log()没有在屏幕上打印任何内容,这意味着代码永远不会进入控制台。这可能意味着在执行datepicker代码之前发生了一些错误,编译器永远不会到达这一点。奇怪的是,当我单击字段时,datepicker本身就会显示出来。如果代码中有错误,它通常不会这样做,是吗?