javascript / jquery范围滑块中的语法错误

时间:2012-05-22 13:44:03

标签: javascript jquery slider range

有人会告诉我这行代码中的语法有什么问题吗?在Dreamweaver中,我收到语法错误:

values: [${command.schedule.startTime.minutesFromMidnight},
            ${command.schedule.stopTime.minutesFromMidnight}],

以下完整的javascript代码:

<script language="javascript">
   function slideTime(from_position, to_position){
     var from = parseInt(from_position);
     var to = parseInt(to_position);
     if(from > (23*60)+45) {
     return false;
   }
  if(from >= to) {
     return false;
   }
  var minutes0 = parseInt(from % 60);
  var hours0 = parseInt(from / 60 % 24);
  var minutes1 = parseInt(to % 60);
  var hours1 = parseInt(to / 60 % 24);
  if(getTime(hours0, minutes0) == getTime(hours1, minutes1)){
     to = to - 15;
     minutes1 = parseInt(to % 60);
     hours1 = parseInt(to / 60 % 24);
     }
  $("#time").val(getTime(hours0, minutes0) + ' - ' + getTime(hours1, minutes1));
  $("#schedule\\.startTime\\.minutesFromMidnight").val(from);
  $("#schedule\\.stopTime\\.minutesFromMidnight").val(to);
  }
  function getTime(hours, minutes) {
     var time = null;
     minutes = minutes + "";
     if (hours < 12) {
     time = "AM";
     }
     else {
     time = "PM";
     }
      if (hours == 0) {
     hours = 12;
     }
     if (hours > 12) {
     hours = hours - 12;
     }
     if (minutes.length == 1) {
     minutes = "0" + minutes;
     }
      return hours + ":" + minutes + " " + time;
     } 
</script>


<script language="javascript">
   $(document).ready(function() {
   $("#slider-range").slider({
   range: true,
   min: 0,
   max: 1680,
   values: [${command.schedule.startTime.minutesFromMidnight},
            ${command.schedule.stopTime.minutesFromMidnight}],
   slide: function(event, ui) {
          var from = ui.values[0];
          var to = ui.values[1];
          return slideTime(from, to);
   },
   step:15
   });
 });
</script>

HTML

<div id="slider-range"></div>

代码不会在浏览器中运行。我没有编写代码,但是重新使用了它。感谢。

1 个答案:

答案 0 :(得分:-2)

<script language="javascript">
   function slideTime(from_position, to_position){
     var from = parseInt(from_position);
     var to = parseInt(to_position);
     if(from > (23*60)+45) {
     return false;
   }
  if(from >= to) {
     return false;
   }
  var minutes0 = parseInt(from % 60);
  var hours0 = parseInt(from / 60 % 24);
  var minutes1 = parseInt(to % 60);
  var hours1 = parseInt(to / 60 % 24);
  if(getTime(hours0, minutes0) == getTime(hours1, minutes1)){
     to = to - 15;
     minutes1 = parseInt(to % 60);
     hours1 = parseInt(to / 60 % 24);
     }
  $("#time").val(getTime(hours0, minutes0) + ' - ' + getTime(hours1, minutes1));
  $("#schedule\\.startTime\\.minutesFromMidnight").val(from);
  $("#schedule\\.stopTime\\.minutesFromMidnight").val(to);
  }
  function getTime(hours, minutes) {
     var time = null;
     minutes = minutes + "";
     if (hours < 12) {
     time = "AM";
     }
     else {
     time = "PM";
     }
      if (hours == 0) {
     hours = 12;
     }
     if (hours > 12) {
     hours = hours - 12;
     }
     if (minutes.length == 1) {
     minutes = "0" + minutes;
     }
      return hours + ":" + minutes + " " + time;
     } 
</script>


<script language="javascript">
   $(document).ready(function() {
   $("#slider-range").slider({
   range: true,
   min: 0,
   max: 1680,
   values: [$command.schedule.startTime.minutesFromMidnight,
            $command.schedule.stopTime.minutesFromMidnight],
   slide: function(event, ui) {
          var from = ui.values[0];
          var to = ui.values[1];
          return slideTime(from, to);
   },
   step:15
   });
 });
</script>

使用此代码..