钛工作室我如何提交文本字段?

时间:2012-08-21 14:51:48

标签: titanium-mobile

我正在开发钛工作室的移动应用程序,无法获得原生提交的文本字段

这是我的代码:

  var textField1 = Ti.UI.createTextField({
  borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
  color: '#336699',
  width: 250, height: 60
  });

   textField1.addEventListener('return', function(data) {
   alert('form submitted: ' + data);
   });

  win1.add(textField1);

我是钛工作室的新手,但我相信这应该有用。 任何想法??

2 个答案:

答案 0 :(得分:1)

仅在按下返回按钮时才会触发返回。所以我认为你可以在文本框失去焦点时获得值。

你可以通过以下方式获得价值:

textField1.addEventListener('blur',function(data){
    alert(data.source.value);
});

可以使用alert(JSON.stringify(data));

找到更多详细信息

但是对于'return'监听器,这不会被触发。所以你也可以为'return'包含相同的代码。

textField1.addEventListener('return',function(data){
    alert(data.source.value);
    alert(JSON.stringify(data));
});

答案 1 :(得分:0)

var win = Titanium.UI.createWindow({
    title:"Configuring text field and text area keyboard types",
    backgroundColor:"#347AA9",
    exitOnClose:true
});

var submitButton = Titanium.UI.createButton({
    title:"Submit",
    height:24,
    width:60
});

var textField = Titanium.UI.createTextField({
    top:"25%",
    height:35,
    width:600,
    backgroundColor:"#ffffff",
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
    hintText:"Type something",
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    rightButton:submitButton
});

submitButton.addEventListener("click", function(e){
    //Pretend to submit the value of the text field
    //Be sure that you've typed something in!
    if(textField.value != ""){
        alert(textField.value); 
    }else{
        alert("Enter some text");
    }
});

//Add an event listener to the window that allows for the keyboard or input keys to be hidden if the user taps outside a text field
//Note: each text field to be blurred would be added below
win.addEventListener("click", function(e){
    textField.blur(); // Cause the text field to lose focus, thereby hiding the keyboard (if visible)
});

win.add(textField);

win.open();