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

parseIntと置き換えますNumber

このようになり、動作します...(しかし、私はそれがかなり簡単になると思います...)ここでテスト

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 に答える