0

请告诉我如何在钛中创建一个注册表并将填写该表格的注册数据传递到另一个表格。

4

1 回答 1

1

以下是注册示例代码。我在资源文件夹中创建了一个附加文件“success.js”,显示了第二个窗口。请尝试以下代码

在 app.js 文件中写入这些行

var win1 = Ti.UI.createWindow({
 width : 'auto',
 height: 'auto',
 backgroundColor : '#FFFFFF'
});

var txtName = Ti.UI.createTextField({
 top   : '25%',
 width : '75%',
 height: '35',
 hintText : 'Name'
});

win1.add(txtName);

var txtAddress = Ti.UI.createTextField({
 top   : '35%',
 width : '75%',
 height: '40',
 hintText : 'Address'
});

win1.add(txtAddress);


var btnRegister = Ti.UI.createButton({
 top : '55%',
 width : '50%',
 height : '35',
 title  : 'Register'
});

 win1.add(btnRegister);

 win1.open();
 btnRegister.addEventListener('click', function(){

 var win2 = Ti.UI.createWindow({
  width : 'auto',
  height: 'auto',
  backgroundColor : '#FFFFFF',
  url  : 'success.js'
});

 win2.name = txtName.value;
 win2.address = txtAddress.value; 
 win2.open();
});

// 在 success.js 文件中写入以下行

var win2 = Ti.UI.currentWindow;

var name = win2.name;
var address = win2.address;
var lblName = Ti.UI.createLabel({
  top  : '30%',
  width : '75%',
  height : 'auto',
  color  : 'yellow',
  backgroundColor : 'blue',
  text : name,
  textAlign : 'center'
 });

var lblAddress = Ti.UI.createLabel({
  top  : '40%',
  width : '75%',
  height : 'auto',
  color  : 'yellow',
  backgroundColor : 'blue',
  text : address,
  textAlign : 'center'
 });

 win2.add(lblName);
 win2.add(lblAddress);

现在编译代码并运行。它对我有用。尝试一下

于 2012-10-11T16:13:00.070 回答