extjs完美实现“密码框显示提示文字,不显示输入文字”的变态需求!!!
2016-11-15 14:34
896 查看
先看下需求:“密码框显示提示文字,不显示输入文字”
1、正常状态下:
2、密码框输入密码时:
3、密码框有值的时候,失去鼠标焦点的状态:
4、密码框值为空的时候,失去鼠标焦点的状态:
实现代码:
关键代码:
listeners:{
focus: function(){
document.getElementById('password').type = "password";
},
change: function(){
if (this.getValue() !== ""){
document.getElementById('password').type = "password";
} else {
document.getElementById('password').type = "text";
}
}
}
解释一下:
1、 通过监听输入框的 focus 和 change 这两个事件,分别对输入框获得焦点和输入值这两种情况来改变输入框的类型。
2、那么怎么修改输入框的类型呢?尝试了一下 this.inputType = "password" 然并卵,最终只有这样才行:
document.getElementById('password').type = "你想要的类型";
1、正常状态下:
2、密码框输入密码时:
3、密码框有值的时候,失去鼠标焦点的状态:
4、密码框值为空的时候,失去鼠标焦点的状态:
实现代码:
username:{ cls: "text_field username", inputType: 'text', width: 326, height: 60, emptyText: '账户', emptyClass:"usernameEmpty", focusClass:"usernameSelect", margins:"30 58 0 58", listeners: { } }, password:{ cls: "text_field password", inputType: 'text', width: 326, height: 60, emptyText: '密码', emptyClass:"usernameEmpty", focusClass:"passwordSelect", margins:"30 58 0 58", enableKeyEvents: true, listeners: { keypress: function (field, e) { if (e.getKey() == 13) { Ext.getCmp("loginBtn").el.dom.click(); } }, focus: function(){ document.getElementById('password').type = "password"; }, change: function(){ if (this.getValue() !== ""){ document.getElementById('password').type = "password"; } else { document.getElementById('password').type = "text"; } } } },
关键代码:
listeners:{
focus: function(){
document.getElementById('password').type = "password";
},
change: function(){
if (this.getValue() !== ""){
document.getElementById('password').type = "password";
} else {
document.getElementById('password').type = "text";
}
}
}
解释一下:
1、 通过监听输入框的 focus 和 change 这两个事件,分别对输入框获得焦点和输入值这两种情况来改变输入框的类型。
2、那么怎么修改输入框的类型呢?尝试了一下 this.inputType = "password" 然并卵,最终只有这样才行:
document.getElementById('password').type = "你想要的类型";
相关文章推荐
- 基于JS实现密码框(password)中显示文字提示功能代码
- 设置密码输入框光标未选中为提示文字,输入密码不可见的实现
- 【代码笔记】HTML+CSS+JavaScript实现密码输入框显示文字
- jQuery实现文本域内提示文字,当鼠标点击进文本域后自动消失,文本域失去鼠标焦点后显示提示文字或显示用户输入的文字。
- jquery实现密码框显示提示文字
- 密码框显示提示文字
- 密码框显示提示文字
- 输入框显示输入提示,点击消失。没输入直接提交,提交的输入框内容为空,不提交显示的提示文字
- 在密码输入框里显示提示信息
- 使用jQuery实现显示文字气球的提示
- ngui 实现聊天系统中玩家输入表情与文字结合显示
- 实现网页文本框显示灰色提示文字且点击后消失的一个小函数(基于jquery)
- win32平台下:cocos2d-x中继承并重写CCTextFieldTTF类,实现密码框输入时,*显示
- 设计input搜索框提示文字点击消失的效果,提示文字与输入显示不同----->特别推荐
- 【Android】实现动态显示隐藏密码输入框的内容
- jQuery实现密码输入框点击隐藏框内提示字
- 密码框显示提示文字jquery示例
- 黑马程序员之C#编程基础学习笔记:用while break实现要求用户输入用户名和密码,只要不是admin,888888就一直提示要求重新输入。
- jquery实现微博文字输入框 输入时显示输入字数 效果实现
- android程序代码实现改变字体颜色和输入密码的显示隐藏