这可能只是一个简单的错误,但我花了最后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>
答案 0 :(得分:0)
好吧,似乎您的JavaScript存在某个问题,您必须查看控制台消息以查看出现了什么问题。
无论如何,我想在做出任何评论或完整解决方案之前看到完整的HTML和代码。但是根据您要求保持简单并且看到更改日期已被正确捕获的请求,我们必须遵循以下方法。
$("#id_submission_date").datepicker({
onSelect: function(dateText) {
console.log(dateText);
}
});
这里是&#34; dateText&#34;应包含所需的选定日期。检查浏览器控制台。但是如果出现错误,将显示正确的错误。
获得适当的日期后,您可以进行比较。
如果出现错误,请在此处发布错误消息,我们可以进行更多讨论。