0

我真的很沮丧,因为我对倒数计时器一无所知......当我终于找到这个脚本时,我操纵它以便从分钟和秒而不是几秒开始倒计时......但只需运行它看看问题出在哪里...帮助!!!!

function doGet(e) {
var TIMER_SEC = '3:12';
var app = UiApp.createApplication();
//var button = app.createButton('Start/Pausa');
var timerDisplay = app.createLabel().setId('timerDisplay');
var timerValue = app.createTextBox().setId('timerValue').setName('timerValue').setVisible(false);
var chk = setTime(TIMER_SEC, app, timerDisplay, timerValue);
app.add(timerDisplay);
app.add(timerValue);
app.add(chk);
//app.add(button);
return app;
}

function handleTimer(e){
var app = UiApp.getActiveApplication();
var a;
var b=":0";
var t = e.parameter.timerValue;
var timerDisplay = app.getElementById('timerDisplay');
if(t!='0:00'){
if(t.substr(2,2)=="00"){
a=parseInt(t.substr(0,1))-1;
t=a.toString().concat(':59');
}
else{
a=parseInt(t.substr(2,2))-1;
if(a<10){
t=t.substr(0,1).concat(':0' + a.toString());
}
else{
t=t.substr(0,2).concat(a);
}
}
var timerValue = app.getElementById('timerValue');
var chk = setTime(t, app, timerDisplay, timerValue);
Utilities.sleep(1000);
chk.setValue(true,true);
}
else {
timerDisplay.setText('Finish!');
}
return app;
}

function setTime(time, app, timerDisplay, timerValue) {
timerDisplay.setText(time);
timerValue.setValue(time);
var handlerTimer = app.createServerHandler('handleTimer');
handlerTimer.addCallbackElement(timerValue);
var chk = app.createCheckBox('chk').addValueChangeHandler(handlerTimer).setValue(true,true).setVisible(false);
return chk;
}
4

1 回答 1

0

替换parseIntNumber

变成这样并且可以工作......(但我想它可能会更简单......)在这里测试

function handleTimer(e){
var app = UiApp.getActiveApplication();
var a;
var b=":0";
var t = e.parameter.timerValue;
var timerDisplay = app.getElementById('timerDisplay');
if(t!='0:00'){
if(t.substr(2,2)=="00"){
a=Number(t.substr(0,1))-1;
t=a.toString().concat(':59');
}
else{
a=Number(t.substr(2,2))-1;
if(a<=9){
t=t.substr(0,1).concat(':0' + a.toString());
}
else{
t=t.substr(0,2).concat(a);
}
}
var timerValue = app.getElementById('timerValue');
var chk = setTime(t, app, timerDisplay, timerValue);
Utilities.sleep(1000);
chk.setValue(true,true);
}
else {
timerDisplay.setText('Finish!');
}
return app;
} 

编辑:我猜这个版本有点简单,而且很容易根据您的需要进行定制...... 在这里测试

function doGet() {
  var app = UiApp.createApplication().setTitle('Counter/Timer').setStyleAttribute('padding','35');
  var Panel = app.createVerticalPanel();
  var counter = app.createHTML().setId('counter').setHTML('<B>Timer = wait</B>').setStyleAttribute('fontSize','40px');// set start display
  var clo = app.createTextBox().setName('clo').setId('clo').setValue('192').setVisible(false);//set start value in seconds
  var handler1 = app.createServerHandler('loadData1').addCallbackElement(Panel);
  var chk1 = app.createCheckBox('test1').addValueChangeHandler(handler1).setVisible(true).setId('chk1').setVisible(false);
  app.add(Panel.add(chk1).add(counter).add(clo));
  chk1.setValue(true,true);
  return app}

function loadData1(e) {
  var app = UiApp.getActiveApplication();
  var xx = Number(e.parameter.clo);
  var disp = app.getElementById('counter')
  xx-- ;// replace by xx++ to count upwards
  if(xx<0){ // and change comparison accordingly
  disp.setHTML('Time Over')
  return app
  }
  var cnt = app.getElementById('clo').setValue(xx)
  disp.setHTML('<B>'+T(xx)+'</B>')
  Utilities.sleep(500);
  var chk1 = app.getElementById('chk1').setValue(false,false)
  Utilities.sleep(500);
  var chk1 = app.getElementById('chk1').setValue(true,true)
  return app;
}

function T(val){
  var min = parseInt(val/60);
  var sec = val-(60*min);
  if(sec<10){sec='0'+sec}
  if(min<10){min='0'+min}
  var st = 'Timer = '+min+':'+sec;
  return st
}
于 2013-02-20T20:08:25.260 回答