1

所以我想在单击后根据复选框的值启用或禁用日期框。我可以在服务器端做到这一点,如下所示,但似乎无法弄清楚如何在客户端做到这一点。我的问题是如果不调用服务器,我似乎无法访问复选框的值。有任何想法吗?

var chkPaid = app.createCheckBox("Paid in Full").setName("paidInFull").setId("paidInFull");
var dateBox2 = app.createDateBox().setName("paidThrough").setFormat(UiApp.DateTimeFormat.DATE_MEDIUM).setEnabled(false).setId("paidThru");
var paidThruDisable = app.createServerHandler("disableHandler");
paidThruDisable.addCallbackElement(chkPaid);
chkPaid.addValueChangeHandler(paidThruDisable);

function disableHandler(e){
  var app = UiApp.getActiveApplication();
  var widget = app.getElementById("paidThru");
  if(e.parameter.paidInFull !== "true"){
    widget.setEnabled(false);
  }else{
    widget.setEnabled(true);
  };
  return app;
}
4

1 回答 1

1

这是我写的一段代码,可以解决问题;-)

你可以在这里在线测试

function doGet() {
  var app = UiApp.createApplication()
  var chkPaida = app.createCheckBox("Paid in Full").setValue(true);
  var chkPaidb = app.createCheckBox("Paid in Full").setVisible(false);
  var checkpanel = app.createHorizontalPanel().add(chkPaida).add(chkPaidb)
  var dateBox2 = app.createDateBox().setName("paidThrough").setFormat(UiApp.DateTimeFormat.DATE_MEDIUM).setId("paidThru").setName("paidThru");

  var Chandlera = app.createClientHandler().forTargets(dateBox2).setEnabled(false).forTargets(chkPaidb).setVisible(true).setValue(false)
  .forEventSource().setVisible(false)  
  chkPaida.addClickHandler(Chandlera)

  var Chandlerb = app.createClientHandler().forTargets(dateBox2).setEnabled(true).forTargets(chkPaida).setVisible(true).setValue(true)
  .forEventSource().setVisible(false)  
  chkPaidb.addClickHandler(Chandlerb)

app.add(checkpanel).add(dateBox2)
  return app
}
于 2012-10-23T19:06:58.730 回答