2013-10-29 23 views
0

有誰知道該怎麼做?我有這樣的代碼:如何在textField上使用zIndex,當我在Titanium中按next時,我可以移動到其他textField?

var txtOne = Titanium.UI.createTextField({ 
    top:50, 
    zIndex:1 
}); 

var txtTwo = Titanium.UI.createTextField({ 
    top:100 
}); 

var txtThree = Titanium.UI.createTextField({ 
    top:150, 
    zIndex:2 
}); 

我要的是從txtOne跳轉到txtThree而不去txtTwo ..

我嘗試用zIndex的,但它不是爲我工作..

任何理念??感謝

+0

使用Z指數似乎是一個壞主意開始。這不是它的目的。 –

+0

@timothy Groote:你還有其他想法該怎麼做? –

+0

不知道我的想法是否與這兩種方式一致,但它應該起作用。我爲你發佈了一個答案 –

回答

2

,你可以把它們放到一個數組,併爲其指定事件處理程序的返回功能是這樣的:

var textFields = [txtOne, txtTwo, txtThree]; 

for(vat i=0; i < textFields.length; i++) 
{ 
    //make the last text field jump to the first one when returning 
    if(i == textFields.length-1) 
    { 
     textFields [i].addEventListener('return', function(e) 
     { 
      textFields[0].focus(); 
     }); 
    } 
    else 
    { 
     //jump to the next text fields when returning 
     textFields [i].addEventListener('return', function(e) 
     { 
      textFields[i+1].focus(); 
     }); 
    } 
} 
+0

謝謝你的回答@Timothy Groote ..我會盡力...但仍然想知道zIndex屬性對textfield的作用是什麼.. –

+1

textfield可能具有該屬性,因爲它繼承了鈦的默認視圖對象,它有一個z-索引。 默認情況下,z-index未設置,但如果您設置了z-index,則可以手動確定哪些項目將呈現在前面或後面。 http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.View-property-zIndex –

+0

感謝您的信息提摩太..我會先嚐試您的建議.. :) –

相關問題