2013-05-14 52 views
2

我在钛iPhone应用程序中使用密码字段,如果用户按“?”键,我需要显示输入的密码。释放“?”后按钮和掩码密码字段按钮。我用这些代码点击“?”时如何显示输入的密码按钮

var password = Ti.UI.createTextField 
({ 
    font : {fontSize : 15, fontType: 'HaveticaL TStd', fontWeight: 'roman'}, 
    hintText: "***************", 
    top : 54, 
    left : 107, 
    height : 24, 
    width : 153, 
    passwordMask : true, 
    color : "black", 
    returnKeyType : Titanium.UI.RETURNKEY_DONE, 
    zIndex : 5 
}); 

我用touchstart和touchend事件用于显示密码,即设置passwordMask为假时,发生事件touchstart和重置为真时touchend事件发生。

passwordHintImg.addEventListener('touchstart',function(e){ 
    passwordTxt.passwordMask = false; 
}); 
passwordHintImg.addEventListener('touchend',function(e){ 
    passwordTxt.passwordMask = true; 
}); 

它在密码字段模糊时很好用,但如果密码字段是焦点,我按“?”按钮密码显示,我能不能隐藏显示密码

回答

2

最后,我得到的输出

我用标签显示的密码,并设置明显的假,当touchstart事件发生,我改变passwordShow标签可见真并设置密码字段可见,以禁用,当touchend事件发生时,我将密码字段可见重置为true,密码显示标签可见为false。

var passwordShow = Ti.UI.createLabel({ 
    font : {fontSize : 15, fontType: 'HaveticaL TStd', fontWeight: 'roman'}, 
    top : 54, 
    left : 107, 
    height : 24, 
    width : 153, 
    visible : false, 
    backgroundColor : 'transparent', 
    color : "black", 
    zIndex : 15 
}); 
passwordShowVw.addEventListener('touchstart',function(e){ 
    if(passwordTxt.value.length > 0) 
    { 
     passwordTxt.visible = false; 
     passwordShow.visible = true; 
     passwordShow.text = passwordTxt.value; 
    } 
}); 
passwordShowVw.addEventListener('touchend',function(e){ 
    if(passwordTxt.value.length > 0) 
    { 
     passwordShow.visible = false; 
     passwordTxt.visible = true; 
     passwordShow.text = ''; 
    } 
});