我用 jquery-ui 构建了一个带有日期选择器、一对滑块、一个微调器和一个按钮的小表单。当按下按钮时,表单中的一些值应该通过 POST 发送到服务器。但是我在 Firefox Web Developer Console 上观看,并且没有 POST 发生。我究竟做错了什么?
我使用 Django 作为网络服务器,我的 html 是这样的:
<html>
<head>
<script src="{{STATIC_URL}}js/jquery-1.9.1.js"></script>
<script src="{{STATIC_URL}}js/jquery-ui-1.10.3.custom.js"></script>
<link rel="stylesheet" href="{{STATIC_URL}}css/jquery-ui-1.10.3.custom.css">
<script>
// DatePicker function:
$(function() {
var today = new Date()
$( "#id_startDate" ).datepicker({
minDate: today,
onSelect: function(selectedDate) {
var option = this.id == "id_startDate" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});
// Interval slider function:
$(function() {
var currentHour = new Date().getUTCHours()
$( "#id_interval" ).slider({
range: true,
min: 0,
max: 72,
values: [ currentHour, currentHour+48 ], // By default from current hour 1st day to same hour last day
slide: function( event, ui ) {
var startDay = Math.floor($( "#id_interval" ).slider( "values", 0) / 24) + 1
var startHour = $( "#id_interval" ).slider( "values", 0) % 24
var endDay = Math.floor($( "#id_interval" ).slider( "values", 1) / 24) + 1
var endHour = $( "#id_interval" ).slider( "values", 1) % 24
$( "#amount" ).val( "From " + startHour + ":00h day " + startDay +
" to " + endHour + ":00h day " + endDay + " (UTC)");
}
});
$( "#amount" ).val( "From " + currentHour + ":00h day 1 to " + currentHour + ":00h day 3 (UTC)");
});
// Threshold spinner selector:
$(function() {
var id_threshold = $( "#id_threshold" ).spinner();
id_threshold.spinner( "value", 15 );
id_threshold.spinner( "option", "min", 0 );
$( "button" ).button();
});
// Movie player slider:
$(function() {
$( "#player-slider" ).slider({
range: "min",
value: 0,
min: 0,
max: 1000,
slide: function( event, ui ) {
//$( "#amount" ).val( "$" + ui.value );
}
});
// Modify this line to show somehow the current displayed prediction hour
//$( "#amount" ).val( "$" + $( "#player-slider" ).slider( "value" ) );
});
// Play button
$( "#id_playButton" ).click(function() {
var postdata = {
'startdate': $("#id_startDate").datepicker("getDate"),
'starthour': $("#id_interval").slider("values", 0),
'endhour': $("#id_interval").slider("values", 1),
'threshold': $("#id_threshold").val()
}
$.post('/vpl/', postdata)
});
</script>
</head>
<body>
<p>Start Date: <input type="text" id="id_startDate"></p>
<p>
<label for="amount">Interval:</label>
<input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>
<p> <div id="id_interval"></div> </p>
<p>
<label for="id_threshold">Threshold:</label>
<input id="id_threshold" name="value" />
</p>
<p> <div id="player-slider"></div> </p>
<p>
<p>
<button id="id_playButton">Play</button>
</p>
</p>
</body>
</html>
额外的球:当日期选择器出现时,两个滑块标记都停留在日期选择器上方,这有点烦人。对此也有任何想法吗?