English 中文(简体)
javascamp/jquery 区域滑动器中的语法错误
原标题:syntax error in javascript/jquery range slider

有人能告诉我这行代码的语法有什么问题吗?

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

下面是完整的正本代码 :

<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 HTML

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

代码不会在浏览器里运行。 我没有写代码, 但是它交给我重新使用。 谢谢。

问题回答
<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>

使用这个代码...





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签