我在钛 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事件来显示密码,即当touchstart事件发生时将passwordMask设置为false,当touchend事件发生时将passwordMask重置为true。
passwordHintImg.addEventListener('touchstart',function(e){
passwordTxt.passwordMask = false;
});
passwordHintImg.addEventListener('touchend',function(e){
passwordTxt.passwordMask = true;
});
当密码字段模糊时效果很好,但如果密码字段聚焦,我按“?”按钮显示密码,我无法隐藏显示的密码
最佳答案
最后,我得到了输出
我使用标签来显示密码并将可见设置为 false,当 touchstart 事件发生时,我将 passwordShow Label 可见更改为 true 并将密码字段可见设置为禁用,当 touchend 事件发生时,我将密码字段可见重置为 true,passwordShow 标签可见错误。
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 = '';
}
});
关于titanium - 单击 "?"按钮时如何显示输入的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16538705/