下面的 javascript 在表单中创建了一个滑块,该滑块在同一页面上具有提交代码。
表单中显示来自 javascript 的滑块的代码是
<div id="outbox-bottom">Callback time selected <span style="font-size:9px">(Ex Weekends):</span> <span id="callback_selected"></span></div>
我需要一种方法将在滑块上选择的时间转换为一个变量,我可以用它来获取我的表单,如$time = $_POST['time'];
<script type="text/javascript">
jQuery.noConflict();
jQuery(function() {
jQuery('#callback_selected').html("9 am");
var select = jQuery( "#callback" );
var slider = jQuery( "<div id='slider'></div>" ).insertAfter( select ).slider({
min: 1,
max: 12,
range: "min",
value: 1,
step: .5,
slide: function (event, ui) {
$time_int = ui.value;
if (ui.value < 5) {
$time_int = $time_int + 8;
if ($time_int.toString().substr(-2) == '.5') $time_int = $time_int.toString().split('.')[0] + ":30";
$time_selected = $time_int + " am";
} else {
$time_int = $time_int - 4;
if ($time_int.toString().substr(-2) == '.5') $time_int = $time_int.toString().split('.')[0] + ":30";
$time_selected = $time_int + " pm";
}
jQuery('#callback_selected').html($time_selected);
}
});
});
</script>